Skip to content

Commit 49b712f

Browse files
committed
release
1 parent 7ffba1c commit 49b712f

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

react-i18next.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3439,10 +3439,9 @@
34393439
useSuspense,
34403440
keyPrefix
34413441
} = i18nOptions;
3442-
const namespaces = React.useMemo(() => {
3443-
const nsOrContext = ns || defaultNSFromContext || i18n?.options?.defaultNS;
3444-
return isString(nsOrContext) ? [nsOrContext] : nsOrContext || ['translation'];
3445-
}, [ns, defaultNSFromContext, i18n]);
3442+
const nsOrContext = ns || defaultNSFromContext || i18n?.options?.defaultNS;
3443+
const unstableNamespaces = isString(nsOrContext) ? [nsOrContext] : nsOrContext || ['translation'];
3444+
const namespaces = React.useMemo(() => unstableNamespaces, unstableNamespaces);
34463445
i18n?.reportNamespaces?.addUsedNamespaces?.(namespaces);
34473446
const revisionRef = React.useRef(0);
34483447
const subscribe = React.useCallback(callback => {

react-i18next.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/useTranslation.spec.jsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,12 @@ describe('useTranslation', () => {
325325
i18n.loadNamespaces = vitest.fn();
326326

327327
let renderCount = 0;
328+
const countCalls = [];
328329
// Create a hook wrapper that forces re-renders by prop
329330
const { rerender } = renderHook(
330331
({ count }) => {
331-
renderCount++;
332+
countCalls.push(count);
333+
renderCount += 1;
332334
// Inline array: New reference every render
333335
useTranslation(['ns1'], { i18n });
334336
},
@@ -337,11 +339,20 @@ describe('useTranslation', () => {
337339

338340
// Initial render
339341
expect(i18n.loadNamespaces).toHaveBeenCalledTimes(1);
342+
expect(renderCount).to.eql(1);
343+
expect(countCalls).to.have.lengthOf(1);
344+
expect(countCalls[0]).to.eql(0);
340345

341346
rerender({ count: 1 });
342347
expect(i18n.loadNamespaces).toHaveBeenCalledTimes(1);
348+
expect(renderCount).to.eql(2);
349+
expect(countCalls).to.have.lengthOf(2);
350+
expect(countCalls[1]).to.eql(1);
343351

344352
rerender({ count: 2 });
345353
expect(i18n.loadNamespaces).toHaveBeenCalledTimes(1);
354+
expect(renderCount).to.eql(3);
355+
expect(countCalls).to.have.lengthOf(3);
356+
expect(countCalls[2]).to.eql(2);
346357
});
347358
});

0 commit comments

Comments
 (0)