@bleedingdev/modern-js-plugin-i18n 3.4.0-ultramodern.9 → 3.5.0-ultramodern.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37,7 +37,13 @@ const external_react_namespaceObject = require("react");
37
37
  const index_js_namespaceObject = require("./i18n/detection/index.js");
38
38
  const external_routerAdapter_js_namespaceObject = require("./routerAdapter.js");
39
39
  const external_utils_js_namespaceObject = require("./utils.js");
40
- const ModernI18nContext = /*#__PURE__*/ (0, external_react_namespaceObject.createContext)(null);
40
+ const modernI18nContextKey = Symbol.for('@modern-js/plugin-i18n/runtime/ModernI18nContext');
41
+ const getModernI18nContext = ()=>{
42
+ const globalStore = globalThis;
43
+ globalStore[modernI18nContextKey] ??= /*#__PURE__*/ (0, external_react_namespaceObject.createContext)(null);
44
+ return globalStore[modernI18nContextKey];
45
+ };
46
+ const ModernI18nContext = getModernI18nContext();
41
47
  const ModernI18nProvider = ({ children, value })=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ModernI18nContext.Provider, {
42
48
  value: value,
43
49
  children: children
@@ -4,7 +4,13 @@ import { createContext, useCallback, useContext, useEffect, useMemo } from "reac
4
4
  import { cacheUserLanguage } from "./i18n/detection/index.mjs";
5
5
  import { useI18nRouterAdapter } from "./routerAdapter.mjs";
6
6
  import { buildLocalizedUrl, detectLanguageFromPath, getEntryPath, shouldIgnoreRedirect } from "./utils.mjs";
7
- const ModernI18nContext = /*#__PURE__*/ createContext(null);
7
+ const modernI18nContextKey = Symbol.for('@modern-js/plugin-i18n/runtime/ModernI18nContext');
8
+ const getModernI18nContext = ()=>{
9
+ const globalStore = globalThis;
10
+ globalStore[modernI18nContextKey] ??= /*#__PURE__*/ createContext(null);
11
+ return globalStore[modernI18nContextKey];
12
+ };
13
+ const ModernI18nContext = getModernI18nContext();
8
14
  const ModernI18nProvider = ({ children, value })=>/*#__PURE__*/ jsx(ModernI18nContext.Provider, {
9
15
  value: value,
10
16
  children: children
@@ -5,7 +5,13 @@ import { createContext, useCallback, useContext, useEffect, useMemo } from "reac
5
5
  import { cacheUserLanguage } from "./i18n/detection/index.mjs";
6
6
  import { useI18nRouterAdapter } from "./routerAdapter.mjs";
7
7
  import { buildLocalizedUrl, detectLanguageFromPath, getEntryPath, shouldIgnoreRedirect } from "./utils.mjs";
8
- const ModernI18nContext = /*#__PURE__*/ createContext(null);
8
+ const modernI18nContextKey = Symbol.for('@modern-js/plugin-i18n/runtime/ModernI18nContext');
9
+ const getModernI18nContext = ()=>{
10
+ const globalStore = globalThis;
11
+ globalStore[modernI18nContextKey] ??= /*#__PURE__*/ createContext(null);
12
+ return globalStore[modernI18nContextKey];
13
+ };
14
+ const ModernI18nContext = getModernI18nContext();
9
15
  const ModernI18nProvider = ({ children, value })=>/*#__PURE__*/ jsx(ModernI18nContext.Provider, {
10
16
  value: value,
11
17
  children: children
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "modern",
18
18
  "modern.js"
19
19
  ],
20
- "version": "3.4.0-ultramodern.9",
20
+ "version": "3.5.0-ultramodern.1",
21
21
  "engines": {
22
22
  "node": ">=20"
23
23
  },
@@ -97,15 +97,15 @@
97
97
  "i18next-fs-backend": "^2.6.6",
98
98
  "i18next-http-backend": "^4.0.0",
99
99
  "i18next-http-middleware": "^3.9.7",
100
- "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.4.0-ultramodern.9",
101
- "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.4.0-ultramodern.9",
102
- "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.4.0-ultramodern.9",
103
- "@modern-js/server-runtime": "npm:@bleedingdev/modern-js-server-runtime@3.4.0-ultramodern.9",
104
- "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.4.0-ultramodern.9",
105
- "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.4.0-ultramodern.9"
100
+ "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.5.0-ultramodern.1",
101
+ "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.5.0-ultramodern.1",
102
+ "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.5.0-ultramodern.1",
103
+ "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.5.0-ultramodern.1",
104
+ "@modern-js/server-runtime": "npm:@bleedingdev/modern-js-server-runtime@3.5.0-ultramodern.1",
105
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.1"
106
106
  },
107
107
  "peerDependencies": {
108
- "@modern-js/runtime": "3.4.0-ultramodern.9",
108
+ "@modern-js/runtime": "3.5.0-ultramodern.1",
109
109
  "i18next": ">=26.3.1",
110
110
  "react": "^19.2.7",
111
111
  "react-dom": "^19.2.7",
@@ -129,8 +129,8 @@
129
129
  "react-i18next": "17.0.8",
130
130
  "ts-node": "^10.9.2",
131
131
  "typescript": "^6.0.3",
132
- "@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.4.0-ultramodern.9",
133
- "@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.4.0-ultramodern.9"
132
+ "@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.5.0-ultramodern.1",
133
+ "@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.5.0-ultramodern.1"
134
134
  },
135
135
  "sideEffects": false,
136
136
  "publishConfig": {
@@ -32,7 +32,24 @@ export interface ModernI18nContextValue {
32
32
  updateLanguage?: (newLang: string) => void;
33
33
  }
34
34
 
35
- const ModernI18nContext = createContext<ModernI18nContextValue | null>(null);
35
+ const modernI18nContextKey = Symbol.for(
36
+ '@modern-js/plugin-i18n/runtime/ModernI18nContext',
37
+ );
38
+
39
+ type ModernI18nGlobal = typeof globalThis & {
40
+ [key: symbol]:
41
+ | ReturnType<typeof createContext<ModernI18nContextValue | null>>
42
+ | undefined;
43
+ };
44
+
45
+ const getModernI18nContext = () => {
46
+ const globalStore = globalThis as ModernI18nGlobal;
47
+ globalStore[modernI18nContextKey] ??=
48
+ createContext<ModernI18nContextValue | null>(null);
49
+ return globalStore[modernI18nContextKey];
50
+ };
51
+
52
+ const ModernI18nContext = getModernI18nContext();
36
53
 
37
54
  export interface ModernI18nProviderProps {
38
55
  children: ReactNode;
@@ -28,6 +28,15 @@ describe('react-i18next runtime boundary', () => {
28
28
  expect(core).toContain("import('./i18n/utils')");
29
29
  });
30
30
 
31
+ test('keeps the Modern i18n context stable across federated runtime copies', () => {
32
+ const context = readRuntimeSource('context.tsx');
33
+
34
+ expect(context).toContain(
35
+ "Symbol.for(\n '@modern-js/plugin-i18n/runtime/ModernI18nContext'",
36
+ );
37
+ expect(context).toContain('globalStore[modernI18nContextKey] ??=');
38
+ });
39
+
31
40
  test('keeps the default runtime entry wired to react-i18next integration', () => {
32
41
  const defaultEntry = readRuntimeSource('index.tsx');
33
42