@bleedingdev/modern-js-plugin-i18n 3.9.0-ultramodern.17 → 3.9.0-ultramodern.19

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.
@@ -29,9 +29,9 @@ var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
30
  __webpack_require__.d(__webpack_exports__, {
31
31
  FederatedI18nBoundary: ()=>FederatedI18nBoundary,
32
- ModernI18nContext: ()=>ModernI18nContext,
32
+ ModernI18nContext: ()=>external_sharedContexts_js_namespaceObject.ModernI18nContext,
33
33
  ModernI18nProvider: ()=>ModernI18nProvider,
34
- ReactI18nextProviderContext: ()=>ReactI18nextProviderContext,
34
+ ReactI18nextProviderContext: ()=>external_sharedContexts_js_namespaceObject.ReactI18nextProviderContext,
35
35
  getActualI18nextInstance: ()=>instance_js_namespaceObject.getActualI18nextInstance,
36
36
  useModernI18n: ()=>useModernI18n
37
37
  });
@@ -40,22 +40,14 @@ const context_namespaceObject = require("@modern-js/runtime/context");
40
40
  const external_react_namespaceObject = require("react");
41
41
  const external_contextHelpers_js_namespaceObject = require("./contextHelpers.js");
42
42
  const external_routerAdapter_js_namespaceObject = require("./routerAdapter.js");
43
+ const external_sharedContexts_js_namespaceObject = require("./sharedContexts.js");
43
44
  const instance_js_namespaceObject = require("./i18n/instance.js");
44
- const modernI18nContextKey = Symbol.for('@modern-js/plugin-i18n/runtime/ModernI18nContext');
45
- const reactI18nextProviderContextKey = Symbol.for('@modern-js/plugin-i18n/runtime/ReactI18nextProviderContext');
46
- const getGlobalContext = (key, defaultValue)=>{
47
- const globalStore = globalThis;
48
- globalStore[key] ??= /*#__PURE__*/ (0, external_react_namespaceObject.createContext)(defaultValue);
49
- return globalStore[key];
50
- };
51
- const ModernI18nContext = getGlobalContext(modernI18nContextKey, null);
52
- const ReactI18nextProviderContext = getGlobalContext(reactI18nextProviderContextKey, null);
53
45
  const ModernI18nProvider = ({ children, i18nextProvider, value })=>{
54
- const content = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ModernI18nContext.Provider, {
46
+ const content = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_sharedContexts_js_namespaceObject.ModernI18nContext.Provider, {
55
47
  value: value,
56
48
  children: children
57
49
  });
58
- return void 0 === i18nextProvider ? content : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ReactI18nextProviderContext.Provider, {
50
+ return void 0 === i18nextProvider ? content : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_sharedContexts_js_namespaceObject.ReactI18nextProviderContext.Provider, {
59
51
  value: i18nextProvider,
60
52
  children: content
61
53
  });
@@ -74,7 +66,7 @@ const FederatedI18nBoundary = (props)=>{
74
66
  });
75
67
  };
76
68
  const useModernI18n = ()=>{
77
- const context = (0, external_react_namespaceObject.useContext)(ModernI18nContext);
69
+ const context = (0, external_react_namespaceObject.useContext)(external_sharedContexts_js_namespaceObject.ModernI18nContext);
78
70
  if (!context) throw new Error('useModernI18n must be used within ModernI18nProvider');
79
71
  const { language: contextLanguage, i18nInstance, languages, localePathRedirect, ignoreRedirectRoutes, urlStrategy, updateLanguage, synchronizeLanguage } = context;
80
72
  const { navigate, location, hasRouter } = (0, external_routerAdapter_js_namespaceObject.useI18nRouterAdapter)();
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ I18nNavigationContext: ()=>I18nNavigationContext,
32
+ ModernI18nContext: ()=>ModernI18nContext,
33
+ ReactI18nextProviderContext: ()=>ReactI18nextProviderContext
34
+ });
35
+ const external_react_namespaceObject = require("react");
36
+ const ModernI18nContext = (0, external_react_namespaceObject.createContext)(null);
37
+ const ReactI18nextProviderContext = (0, external_react_namespaceObject.createContext)(null);
38
+ const I18nNavigationContext = (0, external_react_namespaceObject.createContext)(null);
39
+ exports.I18nNavigationContext = __webpack_exports__.I18nNavigationContext;
40
+ exports.ModernI18nContext = __webpack_exports__.ModernI18nContext;
41
+ exports.ReactI18nextProviderContext = __webpack_exports__.ReactI18nextProviderContext;
42
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
43
+ "I18nNavigationContext",
44
+ "ModernI18nContext",
45
+ "ReactI18nextProviderContext"
46
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
47
+ Object.defineProperty(exports, '__esModule', {
48
+ value: true
49
+ });
@@ -33,13 +33,11 @@ __webpack_require__.d(__webpack_exports__, {
33
33
  useNativeI18nRouterAdapter: ()=>useNativeI18nRouterAdapter
34
34
  });
35
35
  const jsx_runtime_namespaceObject = require("react/jsx-runtime");
36
+ const contexts_namespaceObject = require("@modern-js/plugin-i18n/runtime/contexts");
36
37
  const runtime_namespaceObject = require("@modern-js/runtime");
37
38
  const context_namespaceObject = require("@modern-js/runtime/context");
38
39
  const external_react_namespaceObject = require("react");
39
- const navigationContextKey = Symbol.for('@modern-js/plugin-i18n/runtime/I18nNavigationContext');
40
- const contextStore = globalThis;
41
- const I18nNavigationContext = contextStore[navigationContextKey] ??= /*#__PURE__*/ (0, external_react_namespaceObject.createContext)(null);
42
- const I18nNavigationProvider = ({ children, value })=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(I18nNavigationContext.Provider, {
40
+ const I18nNavigationProvider = ({ children, value })=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(contexts_namespaceObject.I18nNavigationContext.Provider, {
43
41
  value: value,
44
42
  children: children
45
43
  });
@@ -66,7 +64,7 @@ const useNativeI18nRouterAdapter = ()=>{
66
64
  };
67
65
  };
68
66
  const useI18nRouterAdapter = ()=>{
69
- const provided = (0, external_react_namespaceObject.useContext)(I18nNavigationContext);
67
+ const provided = (0, external_react_namespaceObject.useContext)(contexts_namespaceObject.I18nNavigationContext);
70
68
  const native = useNativeI18nRouterAdapter();
71
69
  return provided ?? native;
72
70
  };
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
13
+ };
14
+ })();
15
+ (()=>{
16
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.r = (exports1)=>{
20
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
21
+ value: 'Module'
22
+ });
23
+ Object.defineProperty(exports1, '__esModule', {
24
+ value: true
25
+ });
26
+ };
27
+ })();
28
+ var __webpack_exports__ = {};
29
+ __webpack_require__.r(__webpack_exports__);
30
+ __webpack_require__.d(__webpack_exports__, {
31
+ ModernI18nContext: ()=>contexts_namespaceObject.ModernI18nContext,
32
+ ReactI18nextProviderContext: ()=>contexts_namespaceObject.ReactI18nextProviderContext
33
+ });
34
+ const contexts_namespaceObject = require("@modern-js/plugin-i18n/runtime/contexts");
35
+ exports.ModernI18nContext = __webpack_exports__.ModernI18nContext;
36
+ exports.ReactI18nextProviderContext = __webpack_exports__.ReactI18nextProviderContext;
37
+ for(var __rspack_i in __webpack_exports__)if (-1 === [
38
+ "ModernI18nContext",
39
+ "ReactI18nextProviderContext"
40
+ ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
41
+ Object.defineProperty(exports, '__esModule', {
42
+ value: true
43
+ });
@@ -1,17 +1,9 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
2
  import { RuntimeComponentResolverContext } from "@modern-js/runtime/context";
3
- import { createContext, useCallback, useContext, useEffect, useMemo } from "react";
3
+ import { useCallback, useContext, useEffect, useMemo } from "react";
4
4
  import { changeModernI18nLanguage, getPathLanguage, isI18nLanguageSupported, isI18nResourcesReady, translateI18n } from "./contextHelpers.mjs";
5
5
  import { useI18nRouterAdapter } from "./routerAdapter.mjs";
6
- const modernI18nContextKey = Symbol.for('@modern-js/plugin-i18n/runtime/ModernI18nContext');
7
- const reactI18nextProviderContextKey = Symbol.for('@modern-js/plugin-i18n/runtime/ReactI18nextProviderContext');
8
- const getGlobalContext = (key, defaultValue)=>{
9
- const globalStore = globalThis;
10
- globalStore[key] ??= /*#__PURE__*/ createContext(defaultValue);
11
- return globalStore[key];
12
- };
13
- const ModernI18nContext = getGlobalContext(modernI18nContextKey, null);
14
- const ReactI18nextProviderContext = getGlobalContext(reactI18nextProviderContextKey, null);
6
+ import { ModernI18nContext, ReactI18nextProviderContext } from "./sharedContexts.mjs";
15
7
  const ModernI18nProvider = ({ children, i18nextProvider, value })=>{
16
8
  const content = /*#__PURE__*/ jsx(ModernI18nContext.Provider, {
17
9
  value: value,
@@ -0,0 +1,5 @@
1
+ import { createContext } from "react";
2
+ const ModernI18nContext = createContext(null);
3
+ const ReactI18nextProviderContext = createContext(null);
4
+ const I18nNavigationContext = createContext(null);
5
+ export { I18nNavigationContext, ModernI18nContext, ReactI18nextProviderContext };
@@ -1,10 +1,8 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
+ import { I18nNavigationContext } from "@modern-js/plugin-i18n/runtime/contexts";
2
3
  import { RuntimeContext, isBrowser } from "@modern-js/runtime";
3
4
  import { InternalRuntimeContext } from "@modern-js/runtime/context";
4
- import { createContext, useContext } from "react";
5
- const navigationContextKey = Symbol.for('@modern-js/plugin-i18n/runtime/I18nNavigationContext');
6
- const contextStore = globalThis;
7
- const I18nNavigationContext = contextStore[navigationContextKey] ??= /*#__PURE__*/ createContext(null);
5
+ import { useContext } from "react";
8
6
  const I18nNavigationProvider = ({ children, value })=>/*#__PURE__*/ jsx(I18nNavigationContext.Provider, {
9
7
  value: value,
10
8
  children: children
@@ -0,0 +1 @@
1
+ export { ModernI18nContext, ReactI18nextProviderContext } from "@modern-js/plugin-i18n/runtime/contexts";
@@ -1,18 +1,10 @@
1
1
  import "node:module";
2
2
  import { jsx } from "react/jsx-runtime";
3
3
  import { RuntimeComponentResolverContext } from "@modern-js/runtime/context";
4
- import { createContext, useCallback, useContext, useEffect, useMemo } from "react";
4
+ import { useCallback, useContext, useEffect, useMemo } from "react";
5
5
  import { changeModernI18nLanguage, getPathLanguage, isI18nLanguageSupported, isI18nResourcesReady, translateI18n } from "./contextHelpers.mjs";
6
6
  import { useI18nRouterAdapter } from "./routerAdapter.mjs";
7
- const modernI18nContextKey = Symbol.for('@modern-js/plugin-i18n/runtime/ModernI18nContext');
8
- const reactI18nextProviderContextKey = Symbol.for('@modern-js/plugin-i18n/runtime/ReactI18nextProviderContext');
9
- const getGlobalContext = (key, defaultValue)=>{
10
- const globalStore = globalThis;
11
- globalStore[key] ??= /*#__PURE__*/ createContext(defaultValue);
12
- return globalStore[key];
13
- };
14
- const ModernI18nContext = getGlobalContext(modernI18nContextKey, null);
15
- const ReactI18nextProviderContext = getGlobalContext(reactI18nextProviderContextKey, null);
7
+ import { ModernI18nContext, ReactI18nextProviderContext } from "./sharedContexts.mjs";
16
8
  const ModernI18nProvider = ({ children, i18nextProvider, value })=>{
17
9
  const content = /*#__PURE__*/ jsx(ModernI18nContext.Provider, {
18
10
  value: value,
@@ -0,0 +1,6 @@
1
+ import "node:module";
2
+ import { createContext } from "react";
3
+ const ModernI18nContext = createContext(null);
4
+ const ReactI18nextProviderContext = createContext(null);
5
+ const I18nNavigationContext = createContext(null);
6
+ export { I18nNavigationContext, ModernI18nContext, ReactI18nextProviderContext };
@@ -1,11 +1,9 @@
1
1
  import "node:module";
2
2
  import { jsx } from "react/jsx-runtime";
3
+ import { I18nNavigationContext } from "@modern-js/plugin-i18n/runtime/contexts";
3
4
  import { RuntimeContext, isBrowser } from "@modern-js/runtime";
4
5
  import { InternalRuntimeContext } from "@modern-js/runtime/context";
5
- import { createContext, useContext } from "react";
6
- const navigationContextKey = Symbol.for('@modern-js/plugin-i18n/runtime/I18nNavigationContext');
7
- const contextStore = globalThis;
8
- const I18nNavigationContext = contextStore[navigationContextKey] ??= /*#__PURE__*/ createContext(null);
6
+ import { useContext } from "react";
9
7
  const I18nNavigationProvider = ({ children, value })=>/*#__PURE__*/ jsx(I18nNavigationContext.Provider, {
10
8
  value: value,
11
9
  children: children
@@ -0,0 +1,2 @@
1
+ import "node:module";
2
+ export { ModernI18nContext, ReactI18nextProviderContext } from "@modern-js/plugin-i18n/runtime/contexts";
@@ -2,6 +2,7 @@ import type { ComponentType, FC, ReactNode } from 'react';
2
2
  import type { I18nUrlStrategy } from '../shared/urlStrategy.js';
3
3
  import type { I18nInstance } from './i18n/index.js';
4
4
  import type { Resources } from './i18n/instance.js';
5
+ import { ModernI18nContext, ReactI18nextProviderContext } from './sharedContexts.js';
5
6
  export { getActualI18nextInstance } from './i18n/instance.js';
6
7
  export interface ModernI18nContextValue {
7
8
  language: string;
@@ -14,8 +15,7 @@ export interface ModernI18nContextValue {
14
15
  updateLanguage?: (newLang: string) => void;
15
16
  synchronizeLanguage?: (newLang: string) => void;
16
17
  }
17
- export declare const ModernI18nContext: import("react").Context<ModernI18nContextValue | null>;
18
- export declare const ReactI18nextProviderContext: import("react").Context<ComponentType<any> | null>;
18
+ export { ModernI18nContext, ReactI18nextProviderContext };
19
19
  export interface ModernI18nProviderProps {
20
20
  children: ReactNode;
21
21
  i18nextProvider?: ComponentType<any> | null;
@@ -0,0 +1,6 @@
1
+ import type { ComponentType } from 'react';
2
+ import type { ModernI18nContextValue } from './context.js';
3
+ import type { I18nRouterAdapter } from './routerAdapter.js';
4
+ export declare const ModernI18nContext: import("react").Context<ModernI18nContextValue | null>;
5
+ export declare const ReactI18nextProviderContext: import("react").Context<ComponentType<any> | null>;
6
+ export declare const I18nNavigationContext: import("react").Context<I18nRouterAdapter | null>;
@@ -0,0 +1 @@
1
+ export { ModernI18nContext, ReactI18nextProviderContext, } from './contexts.js';
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "modern",
18
18
  "modern.js"
19
19
  ],
20
- "version": "3.9.0-ultramodern.17",
20
+ "version": "3.9.0-ultramodern.19",
21
21
  "engines": {
22
22
  "node": ">=20"
23
23
  },
@@ -55,6 +55,13 @@
55
55
  },
56
56
  "default": "./dist/esm/runtime/context.mjs"
57
57
  },
58
+ "./runtime/contexts": {
59
+ "types": "./dist/types/runtime/contexts.d.ts",
60
+ "node": {
61
+ "module": "./dist/esm/runtime/contexts.mjs"
62
+ },
63
+ "default": "./dist/esm/runtime/contexts.mjs"
64
+ },
58
65
  "./runtime/no-react-i18next": {
59
66
  "types": "./dist/types/runtime/no-react-i18next.d.ts",
60
67
  "node": {
@@ -104,6 +111,9 @@
104
111
  "runtime/consumer": [
105
112
  "./dist/types/runtime/context.d.ts"
106
113
  ],
114
+ "runtime/contexts": [
115
+ "./dist/types/runtime/contexts.d.ts"
116
+ ],
107
117
  "runtime/no-react-i18next": [
108
118
  "./dist/types/runtime/no-react-i18next.d.ts"
109
119
  ],
@@ -122,13 +132,13 @@
122
132
  }
123
133
  },
124
134
  "dependencies": {
125
- "@modern-js/i18n-runtime-extensions": "npm:@bleedingdev/modern-js-i18n-runtime-extensions@3.9.0-ultramodern.17",
126
- "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.9.0-ultramodern.17",
127
- "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.9.0-ultramodern.17",
128
- "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.9.0-ultramodern.17",
129
- "@modern-js/server-runtime": "npm:@bleedingdev/modern-js-server-runtime@3.9.0-ultramodern.17",
130
- "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.9.0-ultramodern.17",
131
- "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.9.0-ultramodern.17",
135
+ "@modern-js/i18n-runtime-extensions": "npm:@bleedingdev/modern-js-i18n-runtime-extensions@3.9.0-ultramodern.19",
136
+ "@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.9.0-ultramodern.19",
137
+ "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.9.0-ultramodern.19",
138
+ "@modern-js/server-core": "npm:@bleedingdev/modern-js-server-core@3.9.0-ultramodern.19",
139
+ "@modern-js/server-runtime": "npm:@bleedingdev/modern-js-server-runtime@3.9.0-ultramodern.19",
140
+ "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.9.0-ultramodern.19",
141
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.9.0-ultramodern.19",
132
142
  "@swc/helpers": "^0.5.23",
133
143
  "i18next-browser-languagedetector": "^8.2.1",
134
144
  "i18next-chained-backend": "^5.0.6",
@@ -137,7 +147,7 @@
137
147
  "i18next-http-middleware": "^3.9.9"
138
148
  },
139
149
  "peerDependencies": {
140
- "@modern-js/runtime": "3.9.0-ultramodern.17",
150
+ "@modern-js/runtime": "3.9.0-ultramodern.19",
141
151
  "i18next": ">=25.7.4",
142
152
  "react": "^19.2.8",
143
153
  "react-dom": "^19.2.8",
@@ -152,9 +162,9 @@
152
162
  }
153
163
  },
154
164
  "devDependencies": {
155
- "@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.9.0-ultramodern.17",
156
- "@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.9.0-ultramodern.17",
157
- "@modern-js/runtime-extensions": "npm:@bleedingdev/modern-js-runtime-extensions@3.9.0-ultramodern.17",
165
+ "@modern-js/app-tools": "npm:@bleedingdev/modern-js-app-tools@3.9.0-ultramodern.19",
166
+ "@modern-js/runtime": "npm:@bleedingdev/modern-js-runtime@3.9.0-ultramodern.19",
167
+ "@modern-js/runtime-extensions": "npm:@bleedingdev/modern-js-runtime-extensions@3.9.0-ultramodern.19",
158
168
  "@rslib/core": "1.0.2",
159
169
  "@scripts/rstest-config": "2.66.0",
160
170
  "@types/node": "^26.6.2",
@@ -174,6 +184,6 @@
174
184
  "scripts": {
175
185
  "dev": "rslib build --watch",
176
186
  "build": "rslib build",
177
- "test": "rstest --passWithNoTests"
187
+ "test": "rstest"
178
188
  }
179
189
  }
package/rslib.config.mts CHANGED
@@ -1,4 +1,11 @@
1
1
  import { rslibConfig } from '@modern-js/rslib';
2
2
  import { defineConfig } from '@rslib/core';
3
3
 
4
- export default defineConfig(rslibConfig);
4
+ export default defineConfig({
5
+ ...rslibConfig,
6
+ // Keep `@modern-js/plugin-i18n/runtime/contexts` a package self-reference in
7
+ // the output: Module Federation shares the i18n contexts by that request.
8
+ output: {
9
+ externals: ['@modern-js/plugin-i18n/runtime/contexts'],
10
+ },
11
+ });
@@ -1,12 +1,6 @@
1
1
  import { RuntimeComponentResolverContext } from '@modern-js/runtime/context';
2
2
  import type { ComponentType, FC, ReactNode } from 'react';
3
- import {
4
- createContext,
5
- useCallback,
6
- useContext,
7
- useEffect,
8
- useMemo,
9
- } from 'react';
3
+ import { useCallback, useContext, useEffect, useMemo } from 'react';
10
4
  import type { I18nUrlStrategy } from '../shared/urlStrategy';
11
5
  import {
12
6
  changeModernI18nLanguage,
@@ -19,6 +13,10 @@ import type { I18nInstance } from './i18n';
19
13
  import type { Resources } from './i18n/instance';
20
14
 
21
15
  import { useI18nRouterAdapter } from './routerAdapter';
16
+ import {
17
+ ModernI18nContext,
18
+ ReactI18nextProviderContext,
19
+ } from './sharedContexts';
22
20
 
23
21
  export { getActualI18nextInstance } from './i18n/instance';
24
22
 
@@ -36,30 +34,7 @@ export interface ModernI18nContextValue {
36
34
  synchronizeLanguage?: (newLang: string) => void;
37
35
  }
38
36
 
39
- const modernI18nContextKey = Symbol.for(
40
- '@modern-js/plugin-i18n/runtime/ModernI18nContext',
41
- );
42
- const reactI18nextProviderContextKey = Symbol.for(
43
- '@modern-js/plugin-i18n/runtime/ReactI18nextProviderContext',
44
- );
45
-
46
- type GlobalContextStore<T> = typeof globalThis & {
47
- [key: symbol]: ReturnType<typeof createContext<T>> | undefined;
48
- };
49
-
50
- const getGlobalContext = <T,>(key: symbol, defaultValue: T) => {
51
- const globalStore = globalThis as GlobalContextStore<T>;
52
- globalStore[key] ??= createContext<T>(defaultValue);
53
- return globalStore[key];
54
- };
55
-
56
- export const ModernI18nContext =
57
- getGlobalContext<ModernI18nContextValue | null>(modernI18nContextKey, null);
58
- export const ReactI18nextProviderContext =
59
- getGlobalContext<ComponentType<any> | null>(
60
- reactI18nextProviderContextKey,
61
- null,
62
- );
37
+ export { ModernI18nContext, ReactI18nextProviderContext };
63
38
 
64
39
  export interface ModernI18nProviderProps {
65
40
  children: ReactNode;
@@ -0,0 +1,16 @@
1
+ import type { ComponentType } from 'react';
2
+ import { createContext } from 'react';
3
+ import type { ModernI18nContextValue } from './context';
4
+ import type { I18nRouterAdapter } from './routerAdapter';
5
+
6
+ // Every other i18n runtime module imports these through
7
+ // `@modern-js/plugin-i18n/runtime/contexts` so Module Federation shares one
8
+ // copy of them. Their values stay provider-owned.
9
+ export const ModernI18nContext = createContext<ModernI18nContextValue | null>(
10
+ null,
11
+ );
12
+ export const ReactI18nextProviderContext =
13
+ createContext<ComponentType<any> | null>(null);
14
+ export const I18nNavigationContext = createContext<I18nRouterAdapter | null>(
15
+ null,
16
+ );
@@ -1,7 +1,8 @@
1
+ import { I18nNavigationContext } from '@modern-js/plugin-i18n/runtime/contexts';
1
2
  import { isBrowser, RuntimeContext } from '@modern-js/runtime';
2
3
  import { InternalRuntimeContext } from '@modern-js/runtime/context';
3
4
  import type React from 'react';
4
- import { createContext, useContext } from 'react';
5
+ import { useContext } from 'react';
5
6
 
6
7
  interface I18nRouterLocation {
7
8
  pathname: string;
@@ -44,16 +45,6 @@ export interface I18nRouterAdapter {
44
45
  };
45
46
  }
46
47
 
47
- const navigationContextKey = Symbol.for(
48
- '@modern-js/plugin-i18n/runtime/I18nNavigationContext',
49
- );
50
- // Only the React context identity is shared. Its values remain provider-owned.
51
- const contextStore = globalThis as typeof globalThis & {
52
- [navigationContextKey]?: React.Context<I18nRouterAdapter | null>;
53
- };
54
- const I18nNavigationContext = (contextStore[navigationContextKey] ??=
55
- createContext<I18nRouterAdapter | null>(null));
56
-
57
48
  export const I18nNavigationProvider = ({
58
49
  children,
59
50
  value,
@@ -0,0 +1,8 @@
1
+ // Upstream-owned runtime modules take the i18n contexts from this fork-owned
2
+ // module, which reaches them through the shared
3
+ // `@modern-js/plugin-i18n/runtime/contexts` request. That keeps the fork
4
+ // import edge out of the upstream-owned files.
5
+ export {
6
+ ModernI18nContext,
7
+ ReactI18nextProviderContext,
8
+ } from '@modern-js/plugin-i18n/runtime/contexts';
@@ -64,7 +64,7 @@ describe('react-i18next runtime boundary', () => {
64
64
  ).resolves.toBeDefined();
65
65
  });
66
66
 
67
- test('shares Modern i18n context across independently bundled runtime copies', async () => {
67
+ test('independently bundled runtime copies share the contexts subpath', async () => {
68
68
  const tempDir = await mkdtemp(
69
69
  resolve(__dirname, '.modern-i18n-runtime-boundary-'),
70
70
  );
@@ -81,6 +81,9 @@ describe('react-i18next runtime boundary', () => {
81
81
  outfile,
82
82
  packages: 'external',
83
83
  platform: 'node',
84
+ // Resolve the contexts self-reference like an installed package,
85
+ // not through this package's tsconfig `paths`.
86
+ tsconfigRaw: {},
84
87
  });
85
88
  return import(pathToFileURL(outfile).href);
86
89
  }),
@@ -110,6 +113,9 @@ describe('react-i18next runtime boundary', () => {
110
113
  );
111
114
 
112
115
  expect(html).toBe('<span>cs</span>');
116
+ expect(
117
+ Object.getOwnPropertySymbols(globalThis).map(String),
118
+ ).not.toContainEqual(expect.stringContaining('@modern-js/plugin-i18n'));
113
119
  } finally {
114
120
  await rm(tempDir, { force: true, recursive: true });
115
121
  }
package/tsconfig.json CHANGED
@@ -6,9 +6,11 @@
6
6
  "jsx": "preserve",
7
7
  // FORK: `baseUrl` removed. TypeScript 7 / tsgo reject it outright (TS5102),
8
8
  // so this package's own tsconfig could not be typechecked at all. `paths`
9
- // is empty here, so nothing resolved through baseUrl.
9
+ // needs no baseUrl.
10
10
  "isolatedModules": true,
11
- "paths": {},
11
+ "paths": {
12
+ "@modern-js/plugin-i18n/runtime/contexts": ["./src/runtime/contexts.ts"]
13
+ },
12
14
  "rootDir": "./src"
13
15
  },
14
16
  "include": ["src", "types"]