Skip to content

Commit 7221a35

Browse files
committed
fix: ignore if passed an empty i18n instance
1 parent 92d0b19 commit 7221a35

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

__tests__/server-hmr.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,5 +453,15 @@ describe('server-hmr', () => {
453453

454454
expect(getter).toHaveBeenCalledWith({ changedFiles });
455455
});
456+
457+
it('should not fail when getter returns a none i18next instance', () => {
458+
const update = { lang: 'en', ns: 'name-space' };
459+
460+
const getter = jest.fn().mockImplementation(() => null);
461+
const changedFiles = [`${update.lang}/${update.ns}`];
462+
applyServerHMR(getter);
463+
464+
expect(() => whenNativeHMRTriggeredWith(changedFiles)).not.toThrow();
465+
});
456466
});
457467
});

lib/server-hmr.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ module.exports = function applyServerHMR(i18nOrGetter) {
1212
const i18nInstance =
1313
typeof i18nOrGetter === 'function' ? i18nOrGetter({ changedFiles }) : i18nOrGetter;
1414

15+
if (!i18nInstance) {
16+
return;
17+
}
18+
1519
const list = extractList(changedFiles, i18nInstance);
1620

1721
if (list.length === 0) {

0 commit comments

Comments
 (0)