@asteby/metacore-runtime-react 50.0.0 → 50.1.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @asteby/metacore-runtime-react
2
2
 
3
+ ## 50.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 3ee45fd: `@module-federation/vite` (starter-config) y `@module-federation/runtime` (runtime-react) pasan de `dependencies` a `peerDependencies` opcionales. Las apps sin microfrontends ya no los instalan; `runtime-react` carga `@module-federation/runtime` de forma diferida sólo al cargar un addon federado. Migración para apps con federación: agregar explícitamente `@module-federation/vite` (devDependency) y `@module-federation/runtime` (dependency) a su `package.json`. La API no cambia.
8
+
3
9
  ## 50.0.0
4
10
 
5
11
  ### Minor Changes
@@ -1 +1 @@
1
- {"version":3,"file":"addon-loader.d.ts","sourceRoot":"","sources":["../src/addon-loader.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAc3E,MAAM,WAAW,gBAAgB;IAC7B,uEAAuE;IACvE,KAAK,EAAE,MAAM,CAAA;IACb,+EAA+E;IAC/E,GAAG,EAAE,MAAM,CAAA;IACX,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,+DAA+D;IAC/D,GAAG,EAAE,QAAQ,CAAA;IACb;;;;OAIG;IACH,YAAY,CAAC,EAAE,QAAQ,CAAA;IACvB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,wCAAwC;IACxC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,iFAAiF;IACjF,OAAO,CAAC,EAAE,MAAM,IAAI,CAAA;IACpB,+BAA+B;IAC/B,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,KAA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B,EACrB,GAAG,EACH,YAAY,EACZ,QAAQ,EACR,SAAS,EACT,QAAe,EACf,OAAO,EACP,OAAO,EACP,MAAM,EACN,QAAQ,GACX,EAAE,gBAAgB,sCAmElB"}
@@ -10,7 +10,15 @@ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-run
10
10
  // purged, and register() runs again against the new remote. The host shell
11
11
  // (auth, QueryClient, WebSocket, service worker controller) is not touched.
12
12
  import { useEffect, useRef, useState } from 'react';
13
- import { registerRemotes, loadRemote } from '@module-federation/runtime';
13
+ let mfRuntime = null;
14
+ function getMfRuntime() {
15
+ mfRuntime ??= import('@module-federation/runtime').catch((e) => {
16
+ mfRuntime = null;
17
+ throw new Error('Loading federated addons requires the optional peer dependency "@module-federation/runtime" (pnpm add @module-federation/runtime). ' +
18
+ (e instanceof Error ? e.message : String(e)));
19
+ });
20
+ return mfRuntime;
21
+ }
14
22
  import { useDeclareAddonLayout } from './addon-layout-context';
15
23
  import { composeDisposables, disposableFromRegisterResult, markRemoteRegistered, purgeAddonFrontendCache, resolvePluginExports, runDispose, shouldReregisterRemote, } from './addon-fiber';
16
24
  // Derive the `loadRemote` id from the scope + exposed module name. MF resolves
@@ -63,10 +71,10 @@ async function loadAddon(scope, url, module) {
63
71
  // fetches the new remoteEntry. `force: true` wipes that remote's module
64
72
  // cache — without it, loadRemote would keep serving the previous bundle.
65
73
  if (shouldReregisterRemote(scope, url)) {
66
- await withRemoteLoadRetry(() => registerRemotes([{ name: scope, entry: url, type: 'module' }], { force: true }));
74
+ await withRemoteLoadRetry(() => getMfRuntime().then((mf) => mf.registerRemotes([{ name: scope, entry: url, type: 'module' }], { force: true })));
67
75
  markRemoteRegistered(scope, url);
68
76
  }
69
- return withRemoteLoadRetry(() => loadRemote(remoteId(scope, module)));
77
+ return withRemoteLoadRetry(() => getMfRuntime().then((mf) => mf.loadRemote(remoteId(scope, module))));
70
78
  }
71
79
  export function AddonLoader({ scope, url, module = './register', api, hostRegistry, addonKey, unbindKey, fallback = null, onReady, onError, layout, children, }) {
72
80
  const [status, setStatus] = useState('loading');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asteby/metacore-runtime-react",
3
- "version": "50.0.0",
3
+ "version": "50.1.0",
4
4
  "description": "React runtime for metacore hosts — renders addon contributions dynamically",
5
5
  "repository": {
6
6
  "type": "git",
@@ -20,7 +20,6 @@
20
20
  "@dnd-kit/core": "^6.3.0",
21
21
  "@dnd-kit/sortable": "^10.0.0",
22
22
  "@dnd-kit/utilities": "^3.2.2",
23
- "@module-federation/runtime": "^2.5.0",
24
23
  "@tanstack/react-virtual": "^3.14.13",
25
24
  "recharts": "^2.15.0",
26
25
  "zod": "^4.3.0"
@@ -39,7 +38,8 @@
39
38
  "react-dom": ">=18",
40
39
  "react-i18next": ">=13",
41
40
  "sonner": ">=1.7",
42
- "zustand": ">=5"
41
+ "zustand": ">=5",
42
+ "@module-federation/runtime": ">=2.5"
43
43
  },
44
44
  "peerDependenciesMeta": {
45
45
  "@tanstack/react-router": {
@@ -47,6 +47,9 @@
47
47
  },
48
48
  "react-day-picker": {
49
49
  "optional": true
50
+ },
51
+ "@module-federation/runtime": {
52
+ "optional": true
50
53
  }
51
54
  },
52
55
  "devDependencies": {
@@ -70,7 +73,8 @@
70
73
  "tsx": "^4.21.0",
71
74
  "typescript": "^6.0.0",
72
75
  "vitest": "^4.0.0",
73
- "zustand": "^5.0.0"
76
+ "zustand": "^5.0.0",
77
+ "@module-federation/runtime": "^2.5.0"
74
78
  },
75
79
  "scripts": {
76
80
  "build": "tsc -p tsconfig.json",
@@ -9,7 +9,20 @@
9
9
  // purged, and register() runs again against the new remote. The host shell
10
10
  // (auth, QueryClient, WebSocket, service worker controller) is not touched.
11
11
  import { useEffect, useRef, useState } from 'react'
12
- import { registerRemotes, loadRemote } from '@module-federation/runtime'
12
+ // `@module-federation/runtime` is an OPTIONAL peer: apps without federated
13
+ // addons never install it. It is loaded lazily, only when an addon is loaded.
14
+ type MfRuntime = typeof import('@module-federation/runtime')
15
+ let mfRuntime: Promise<MfRuntime> | null = null
16
+ function getMfRuntime(): Promise<MfRuntime> {
17
+ mfRuntime ??= import('@module-federation/runtime').catch((e) => {
18
+ mfRuntime = null
19
+ throw new Error(
20
+ 'Loading federated addons requires the optional peer dependency "@module-federation/runtime" (pnpm add @module-federation/runtime). ' +
21
+ (e instanceof Error ? e.message : String(e)),
22
+ )
23
+ })
24
+ return mfRuntime
25
+ }
13
26
  import type { AddonAPI, AddonLayout, Registry } from '@asteby/metacore-sdk'
14
27
  import { useDeclareAddonLayout } from './addon-layout-context'
15
28
  import {
@@ -131,12 +144,16 @@ async function loadAddon(
131
144
  // cache — without it, loadRemote would keep serving the previous bundle.
132
145
  if (shouldReregisterRemote(scope, url)) {
133
146
  await withRemoteLoadRetry(() =>
134
- registerRemotes([{ name: scope, entry: url, type: 'module' }], { force: true }),
147
+ getMfRuntime().then((mf) =>
148
+ mf.registerRemotes([{ name: scope, entry: url, type: 'module' }], { force: true }),
149
+ ),
135
150
  )
136
151
  markRemoteRegistered(scope, url)
137
152
  }
138
153
  return withRemoteLoadRetry(() =>
139
- loadRemote<AddonRegisterModule>(remoteId(scope, module)),
154
+ getMfRuntime().then((mf) =>
155
+ mf.loadRemote<AddonRegisterModule>(remoteId(scope, module)),
156
+ ),
140
157
  )
141
158
  }
142
159