@bleedingdev/modern-js-renderer-octane 3.9.3-ultramodern.7 → 3.9.3-ultramodern.9

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.
Files changed (96) hide show
  1. package/dist/cjs/client.js +56 -6
  2. package/dist/cjs/entry-application.js +7 -2
  3. package/dist/cjs/entry-client.js +3 -0
  4. package/dist/cjs/entry-server.js +13 -5
  5. package/dist/cjs/federation.js +108 -6
  6. package/dist/cjs/i18n/I18nProvider.js +6 -14
  7. package/dist/cjs/i18n/LocalizedLink.js +24 -33
  8. package/dist/cjs/i18n/index.js +0 -3
  9. package/dist/cjs/i18n-external-snapshot.js +645 -0
  10. package/dist/cjs/index.js +4 -4
  11. package/dist/cjs/manifest.js +2 -2
  12. package/dist/cjs/plugin/compiler.js +2 -5
  13. package/dist/cjs/plugin/index.js +2 -2
  14. package/dist/cjs/plugin/profile.js +12 -10
  15. package/dist/cjs/router-client.js +1 -1
  16. package/dist/cjs/router-external-snapshot.js +263 -0
  17. package/dist/cjs/router-handler.js +11 -8
  18. package/dist/cjs/router-server.js +3 -11
  19. package/dist/cjs/router.js +1 -1
  20. package/dist/cjs/routes.js +11 -17
  21. package/dist/cjs/server.js +28 -7
  22. package/dist/cjs/worker-federation-context.js +63 -0
  23. package/dist/cjs/worker-federation-contexts.js +97 -0
  24. package/dist/cjs/worker-federation.js +97 -0
  25. package/dist/esm/client.mjs +56 -6
  26. package/dist/esm/entry-application.mjs +7 -2
  27. package/dist/esm/entry-client.mjs +3 -0
  28. package/dist/esm/entry-server.mjs +11 -6
  29. package/dist/esm/federation.mjs +110 -8
  30. package/dist/esm/i18n/I18nProvider.mjs +7 -15
  31. package/dist/esm/i18n/LocalizedLink.mjs +24 -30
  32. package/dist/esm/i18n/index.mjs +1 -1
  33. package/dist/esm/i18n-external-snapshot.mjs +576 -0
  34. package/dist/esm/index.mjs +4 -4
  35. package/dist/esm/manifest.mjs +2 -2
  36. package/dist/esm/router-client.mjs +1 -1
  37. package/dist/esm/router-external-snapshot.mjs +216 -0
  38. package/dist/esm/router-handler.mjs +11 -8
  39. package/dist/esm/router-server.mjs +0 -1
  40. package/dist/esm/router.mjs +2 -2
  41. package/dist/esm/routes.mjs +11 -17
  42. package/dist/esm/server.mjs +24 -3
  43. package/dist/esm/worker-federation-context.mjs +19 -0
  44. package/dist/esm/worker-federation-contexts.mjs +47 -0
  45. package/dist/esm/worker-federation.mjs +59 -0
  46. package/dist/esm-node/manifest.mjs +2 -2
  47. package/dist/esm-node/plugin/compiler.mjs +2 -5
  48. package/dist/esm-node/plugin/index.mjs +2 -2
  49. package/dist/esm-node/plugin/profile.mjs +12 -10
  50. package/dist/types/client.d.ts +5 -1
  51. package/dist/types/entry-client.d.ts +2 -0
  52. package/dist/types/entry-server.d.ts +4 -1
  53. package/dist/types/federation.d.ts +2 -0
  54. package/dist/types/i18n/LocalizedLink.d.ts +5 -32
  55. package/dist/types/i18n/context.d.ts +1 -1
  56. package/dist/types/i18n/index.d.ts +1 -1
  57. package/dist/types/i18n-external-snapshot.d.ts +43 -0
  58. package/dist/types/index.d.ts +4 -4
  59. package/dist/types/manifest.d.ts +2 -2
  60. package/dist/types/router-external-snapshot.d.ts +10 -0
  61. package/dist/types/router-server.d.ts +0 -2
  62. package/dist/types/server.d.ts +6 -0
  63. package/dist/types/worker-federation-context.d.ts +34 -0
  64. package/dist/types/worker-federation-contexts.d.ts +25 -0
  65. package/dist/types/worker-federation.d.ts +20 -0
  66. package/package.json +84 -22
  67. package/src/client.ts +99 -16
  68. package/src/entry-application.ts +7 -3
  69. package/src/entry-client.ts +10 -0
  70. package/src/entry-server.ts +20 -9
  71. package/src/federation.ts +159 -15
  72. package/src/i18n/I18nProvider.ts +11 -20
  73. package/src/i18n/LocalizedLink.ts +46 -72
  74. package/src/i18n/context.ts +1 -1
  75. package/src/i18n/index.ts +1 -5
  76. package/src/i18n-external-snapshot.ts +803 -0
  77. package/src/index.ts +4 -4
  78. package/src/manifest.ts +2 -2
  79. package/src/plugin/compiler-manifest.cjs +27 -1
  80. package/src/plugin/compiler.ts +6 -14
  81. package/src/plugin/index.ts +4 -2
  82. package/src/plugin/profile.ts +14 -10
  83. package/src/router-client.ts +1 -1
  84. package/src/router-external-snapshot.ts +306 -0
  85. package/src/router-handler.ts +11 -8
  86. package/src/router-server.ts +0 -2
  87. package/src/router.ts +2 -2
  88. package/src/routes.ts +28 -26
  89. package/src/server.ts +45 -5
  90. package/src/worker-federation-context.ts +51 -0
  91. package/src/worker-federation-contexts.ts +91 -0
  92. package/src/worker-federation.ts +120 -0
  93. package/dist/cjs/router-injection.js +0 -139
  94. package/dist/esm/router-injection.mjs +0 -101
  95. package/dist/types/router-injection.d.ts +0 -8
  96. package/src/router-injection.ts +0 -145
@@ -1,10 +1,10 @@
1
1
  import {
2
- canonicalPath,
3
2
  configuredLanguage,
4
3
  localizePath,
5
4
  } from '@modern-js/i18n-runtime-extensions/paths';
6
5
  import { createElement, hookSlots, type OctaneNode, useContext } from 'octane';
7
6
  import {
7
+ type AnyRouter,
8
8
  Link,
9
9
  type LinkComponentProps,
10
10
  useLocation,
@@ -14,41 +14,23 @@ import { I18nContext } from './context';
14
14
 
15
15
  // Plain TypeScript is not rewritten by the Octane compiler: router hooks take
16
16
  // their stable slot explicitly.
17
- const locationSlot = Symbol(hookSlots(1));
17
+ const targetLocationSlot = Symbol(hookSlots(1));
18
18
 
19
- export interface LocalizedLinkProps {
19
+ export interface LocalizedLinkProps
20
+ extends Omit<
21
+ LinkComponentProps<'a', AnyRouter, string, string>,
22
+ 'to' | 'mask' | 'href' | 'publicHref' | '_fromLocation'
23
+ > {
20
24
  /** A canonical, language-agnostic target, e.g. `/products/red-shoe`. */
21
25
  to: string;
22
26
  /** Localize for a specific language instead of the current one. */
23
27
  language?: string;
24
- children?: unknown;
25
- class?: string;
26
- activeProps?: LinkComponentProps<'a'>['activeProps'];
27
- inactiveProps?: LinkComponentProps<'a'>['inactiveProps'];
28
- activeOptions?: LinkComponentProps<'a'>['activeOptions'];
29
- replace?: boolean;
30
- preload?: LinkComponentProps<'a'>['preload'];
31
28
  }
32
29
 
33
30
  /**
34
- * A thin wrapper over the native Octane router `Link`
35
- * (`@octanejs/tanstack-router`'s precompiled `Link.tsrx`) that localizes a
36
- * canonical `to` for the current (or an explicit) language before handing it
37
- * to the real link — the same contract as `@modern-js/plugin-i18n`'s React
38
- * `Link`. It resolves the href itself via the shared pathname helpers, so it
39
- * works with or without the router's i18n `rewrite`. Every link, including
40
- * one to another language, is the native `Link`: navigation, preloading and
41
- * active state stay with the router.
42
- *
43
- * Under the i18n `rewrite` the router matches canonical paths and localizes
44
- * outgoing locations to the current language, so a link to another language
45
- * routes to the canonical `to` and publishes the target language's URL as a
46
- * route mask (the rewrite keeps a mask's explicit language). The entry's
47
- * router language synchronization (`syncWithRouter`) switches the i18next
48
- * instance from the navigated URL, as it does for history navigation.
49
- *
50
- * No JSX: built with `createElement`, matching this package's existing
51
- * style (see `src/routes.ts`).
31
+ * The native router owns client navigation, preloading and active state. Its mask
32
+ * keeps the canonical route while publishing the selected language URL;
33
+ * the entry's i18n router subscription synchronizes the instance on navigation.
52
34
  */
53
35
  export function LocalizedLink(props: LocalizedLinkProps): OctaneNode {
54
36
  const context = useContext(I18nContext);
@@ -58,55 +40,47 @@ export function LocalizedLink(props: LocalizedLinkProps): OctaneNode {
58
40
  );
59
41
  }
60
42
  const router = useRouter();
61
-
62
- // An explicit language must be configured: it becomes the locale prefix.
43
+ const location = useLocation(undefined, targetLocationSlot);
44
+ const { language: requestedLanguage, to, children, ...options } = props;
63
45
  const language =
64
- props.language === undefined
46
+ requestedLanguage === undefined
65
47
  ? context.language
66
- : configuredLanguage(props.language, context.languages);
67
- const href = localizePath(props.to, language, {
68
- languages: [...context.languages],
69
- localisedUrls: context.localisedUrls,
70
- });
71
- const crossLanguage = language !== context.language;
72
- const rewrite = Boolean(router.options.rewrite);
48
+ : configuredLanguage(requestedLanguage, context.languages);
49
+ const externalTarget = to.startsWith('//') || URL.canParse(to);
50
+ const pathname = externalTarget
51
+ ? to
52
+ : localizePath(
53
+ router.buildLocation({
54
+ to,
55
+ from: options.from,
56
+ params: options.params,
57
+ unsafeRelative: options.unsafeRelative,
58
+ _fromLocation: location,
59
+ }).pathname,
60
+ language,
61
+ {
62
+ languages: [...context.languages],
63
+ localisedUrls: context.localisedUrls,
64
+ },
65
+ );
73
66
 
74
67
  return createElement(
75
- Link,
68
+ Link<AnyRouter, string, string, string, string>,
76
69
  {
77
- // Octane's `Link` builds its location from `to` alone. Under the i18n
78
- // router rewrite the router matches canonical paths and localizes the
79
- // public href itself; without it, the localized path is the route path.
80
- to: rewrite ? props.to : href,
81
- ...(rewrite && crossLanguage ? { mask: { to: href } } : {}),
82
- ...(crossLanguage ? { hreflang: language } : {}),
83
- class: props.class,
84
- activeProps: props.activeProps,
85
- inactiveProps: props.inactiveProps,
86
- activeOptions: props.activeOptions,
87
- replace: props.replace,
88
- preload: props.preload,
70
+ ...options,
71
+ to: router.options.rewrite ? to : pathname,
72
+ ...(router.options.rewrite && !externalTarget
73
+ ? {
74
+ mask: {
75
+ to: pathname,
76
+ inheritSearch: true,
77
+ hash: options.hash,
78
+ state: options.state,
79
+ },
80
+ }
81
+ : {}),
82
+ ...(language === context.language ? {} : { hreflang: language }),
89
83
  },
90
- props.children,
91
- );
92
- }
93
-
94
- /**
95
- * Language-invariant active check: `to="/products"` is active whether the
96
- * current location is `/en/products` or `/produkty` under a mapped locale.
97
- */
98
- export function useIsLocalizedActive(canonicalTarget: string): boolean {
99
- const context = useContext(I18nContext);
100
- if (!context) {
101
- throw new Error(
102
- '[renderer-octane] useIsLocalizedActive was used outside of an I18nProvider.',
103
- );
104
- }
105
- const location = useLocation(undefined, locationSlot);
106
- return (
107
- canonicalPath(location.pathname, {
108
- languages: [...context.languages],
109
- localisedUrls: context.localisedUrls,
110
- }) === canonicalTarget
84
+ children,
111
85
  );
112
86
  }
@@ -6,7 +6,7 @@ export type { I18nContextValue, I18nInstanceLike } from './types';
6
6
  /**
7
7
  * Octane's `createContext<T>(defaultValue: T)` requires a default (unlike
8
8
  * Solid 2's default-less form), so a missing provider is detected by
9
- * checking for `null` in `useI18n`/`useIsLocalizedActive` instead — the same
9
+ * checking for `null` in `useI18n`/`LocalizedLink` instead — the same
10
10
  * guard shape `@modern-js/plugin-i18n`'s React `ModernI18nContext` uses.
11
11
  */
12
12
  export const I18nContext = createContext<I18nContextValue | null>(null);
package/src/i18n/index.ts CHANGED
@@ -22,11 +22,7 @@ export {
22
22
  } from '@modern-js/i18n-runtime-extensions/urlRewrite';
23
23
  export { I18nContext } from './context';
24
24
  export { I18nProvider, type I18nProviderProps } from './I18nProvider';
25
- export {
26
- LocalizedLink,
27
- type LocalizedLinkProps,
28
- useIsLocalizedActive,
29
- } from './LocalizedLink';
25
+ export { LocalizedLink, type LocalizedLinkProps } from './LocalizedLink';
30
26
  export {
31
27
  type OctaneLatestLanguageSyncOptions,
32
28
  useLatestLanguageSync,