@fulgurjs/federation 5.9.2 → 6.0.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.
Files changed (100) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/README.en.md +57 -416
  3. package/README.md +56 -446
  4. package/dist/bridge-app-vue.d.cts +1 -1
  5. package/dist/bridge-app-vue.d.ts +1 -1
  6. package/dist/bridge-core.cjs +1 -1
  7. package/dist/bridge-core.js +2 -2
  8. package/dist/bridge-errors.cjs +1 -1
  9. package/dist/bridge-errors.js +1 -1
  10. package/dist/bridge-host-react.cjs +1 -1
  11. package/dist/bridge-host-react.js +3 -3
  12. package/dist/bridge-host-vue.cjs +1 -1
  13. package/dist/bridge-host-vue.js +3 -3
  14. package/dist/bridge-router-react.d.ts +4 -2
  15. package/dist/bridge-router-react.js +95 -9
  16. package/dist/bridge-router-vue.d.ts +24 -5
  17. package/dist/bridge-router-vue.js +4 -5
  18. package/dist/{chunk-YKIFZIBH.js → chunk-77JZ6U6V.js} +1 -1
  19. package/dist/{chunk-Q6V5O5Y6.js → chunk-ENT3BOTX.js} +1 -1
  20. package/dist/{chunk-WRJG2YG6.js → chunk-ZAYNS7YQ.js} +1 -1
  21. package/dist/cli.js +460 -109
  22. package/dist/index.cjs +25 -38
  23. package/dist/index.js +25 -38
  24. package/dist/react.d.ts +194 -101
  25. package/dist/react.js +4 -0
  26. package/dist/runtime-entry.d.ts +9 -174
  27. package/dist/runtime-entry.js +0 -1
  28. package/dist/runtime.js +1 -1
  29. package/dist/vue-adapter.cjs +5 -1
  30. package/dist/vue-adapter.js +5 -1
  31. package/dist/vue.d.ts +576 -0
  32. package/dist/vue.js +8 -0
  33. package/docs/en/migration.md +210 -0
  34. package/docs/en/reference/api.md +534 -0
  35. package/docs/en/reference/errors.md +86 -0
  36. package/docs/{P5-vite7-8 → maintainers/P5-vite7-8}/345/205/274/345/256/271/347/237/251/351/230/265.md +7 -9
  37. package/docs/{webpack-mf- → maintainers/webpack-mf-}/345/257/271/347/205/247/344/270/216/347/274/272/345/217/243.md +10 -10
  38. package/docs/maintainers//346/262/231/347/256/261/350/276/271/347/225/214/345/256/241/350/256/241.md +43 -0
  39. package/docs/zh/migration.md +210 -0
  40. package/docs/zh/reference/api.md +533 -0
  41. package/docs/zh/reference/errors.md +86 -0
  42. package/examples/templates/README.md +1 -1
  43. package/examples/templates/react-host-vue-remote/pnpm-lock.yaml +7 -7
  44. package/examples/templates/react-host-vue-remote/pnpm-workspace.yaml +1 -1
  45. package/examples/templates/react-host-vue-remote/react-host/README.md +2 -2
  46. package/examples/templates/react-host-vue-remote/react-host/package.json +1 -1
  47. package/examples/templates/react-host-vue-remote/react-host/src/main.tsx +2 -2
  48. package/examples/templates/react-host-vue-remote/scripts/dev.config.json +11 -2
  49. package/examples/templates/react-host-vue-remote/vue-remote/package.json +1 -1
  50. package/examples/templates/react-host-vue-remote/vue-remote/src/bridge.ts +1 -1
  51. package/examples/templates/react-react/host/package.json +1 -1
  52. package/examples/templates/react-react/pnpm-lock.yaml +7 -7
  53. package/examples/templates/react-react/pnpm-workspace.yaml +1 -1
  54. package/examples/templates/react-react/remote/package.json +1 -1
  55. package/examples/templates/react-react/scripts/dev.config.json +11 -2
  56. package/examples/templates/showcase/README.md +6 -6
  57. package/examples/templates/showcase/pnpm-lock.yaml +11 -11
  58. package/examples/templates/showcase/pnpm-workspace.yaml +1 -1
  59. package/examples/templates/showcase/react-host/package.json +1 -1
  60. package/examples/templates/showcase/react-host/src/pages/BridgeVuePage.tsx +1 -1
  61. package/examples/templates/showcase/react-host/src/routing.ts +1 -1
  62. package/examples/templates/showcase/react-remote/package.json +1 -1
  63. package/examples/templates/showcase/react-remote/src/bridge.tsx +1 -1
  64. package/examples/templates/showcase/scripts/dev.config.json +22 -4
  65. package/examples/templates/showcase/vue-host/package.json +1 -1
  66. package/examples/templates/showcase/vue-host/src/pages/BridgeReactPage.vue +1 -1
  67. package/examples/templates/showcase/vue-host/src/routing.ts +3 -13
  68. package/examples/templates/showcase/vue-remote/package.json +1 -1
  69. package/examples/templates/showcase/vue-remote/src/bridge.ts +2 -2
  70. package/examples/templates/vue-host-react-remote/pnpm-lock.yaml +7 -7
  71. package/examples/templates/vue-host-react-remote/pnpm-workspace.yaml +1 -1
  72. package/examples/templates/vue-host-react-remote/react-remote/package.json +1 -1
  73. package/examples/templates/vue-host-react-remote/scripts/dev.config.json +11 -2
  74. package/examples/templates/vue-host-react-remote/vue-host/README.md +2 -2
  75. package/examples/templates/vue-host-react-remote/vue-host/package.json +1 -1
  76. package/examples/templates/vue-host-react-remote/vue-host/src/App.vue +2 -2
  77. package/examples/templates/vue-vue/host/package.json +1 -1
  78. package/examples/templates/vue-vue/host/src/main.ts +28 -21
  79. package/examples/templates/vue-vue/host/src/pages/HomePage.vue +1 -1
  80. package/examples/templates/vue-vue/pnpm-lock.yaml +7 -7
  81. package/examples/templates/vue-vue/pnpm-workspace.yaml +1 -1
  82. package/examples/templates/vue-vue/remote/package.json +1 -1
  83. package/examples/templates/vue-vue/scripts/dev.config.json +11 -2
  84. package/package.json +24 -37
  85. package/dist/bridge-core-D37VanBl.d.ts +0 -99
  86. package/dist/bridge-host-react-CGymCzD2.d.ts +0 -35
  87. package/dist/bridge-host-vue-B3GHaQAC.d.ts +0 -32
  88. package/dist/bridge-react.d.ts +0 -14
  89. package/dist/bridge-react.js +0 -3
  90. package/dist/bridge-vue.d.ts +0 -8
  91. package/dist/bridge-vue.js +0 -3
  92. package/dist/bridge.d.ts +0 -18
  93. package/dist/bridge.js +0 -5
  94. package/dist/chunk-GLASM5EX.js +0 -1730
  95. package/dist/chunk-V6EASSCR.js +0 -249
  96. package/dist/chunk-X34EJB4H.js +0 -207
  97. package/docs/API.en.md +0 -339
  98. package/docs/API.md +0 -914
  99. package/docs//346/262/231/347/256/261/350/276/271/347/225/214/345/256/241/350/256/241.md +0 -45
  100. package/docs//350/277/201/347/247/273/346/214/207/345/215/227.md +0 -179
@@ -1,249 +0,0 @@
1
- import {
2
- RoutingChannel,
3
- acquireBridgeSession,
4
- assertBridgeContract,
5
- assertBridgeOptions,
6
- assertBridgeRoutingProtocol,
7
- assertControlledSessionKey,
8
- bridgeHostError,
9
- provideAppContext,
10
- releaseBridgeSession,
11
- resolveBridgeContext,
12
- withBridgeTimeout
13
- } from "./chunk-GLASM5EX.js";
14
-
15
- // src/bridge-host-vue.ts
16
- import { defineComponent, h, onActivated, onBeforeUnmount, onDeactivated, onMounted, ref, shallowRef, toRaw, watch } from "vue";
17
- var assertBridgeRoutingProtocolSpec = (spec, contract) => assertBridgeRoutingProtocol(spec, contract);
18
- function routingKey(routing) {
19
- if (!routing) return void 0;
20
- return routing.basePath + "|" + String(routing.navigation && typeof routing.navigation.navigate === "function");
21
- }
22
- var ERROR_STYLE = {
23
- padding: "16px",
24
- border: "1px solid #fde2e2",
25
- borderRadius: "4px",
26
- background: "#fef0f0",
27
- color: "#c45656",
28
- fontSize: "13px",
29
- lineHeight: "1.6"
30
- };
31
- var BUTTON_STYLE = {
32
- padding: "4px 14px",
33
- marginRight: "8px",
34
- border: "1px solid #c45656",
35
- borderRadius: "4px",
36
- background: "#c45656",
37
- color: "#fff",
38
- fontSize: "13px",
39
- cursor: "pointer"
40
- };
41
- var SECONDARY_BUTTON_STYLE = {
42
- padding: "4px 14px",
43
- border: "1px solid #c45656",
44
- borderRadius: "4px",
45
- background: "#fff",
46
- color: "#c45656",
47
- fontSize: "13px",
48
- cursor: "pointer"
49
- };
50
- var BridgeErrorPlaceholder = defineComponent({
51
- name: "FulgurjsBridgeError",
52
- props: {
53
- error: { type: Object, default: void 0 },
54
- retry: { type: Function, required: false, default: void 0 }
55
- },
56
- setup(props) {
57
- const reloadPage = () => {
58
- window.location.reload();
59
- };
60
- return () => {
61
- const err = props.error;
62
- const code = err?.code ?? "UNKNOWN";
63
- const message = err?.message ?? String(props.error ?? "unknown error");
64
- return h("div", { style: ERROR_STYLE, "data-fulgurjs-error": code }, [
65
- h("p", { style: "margin:0 0 4px;font-weight:600" }, `\u6865\u63A5\u5E94\u7528\u52A0\u8F7D\u5931\u8D25\uFF08\u9519\u8BEF\u7801 ${code}\uFF09`),
66
- h("p", { style: "margin:0 0 8px;word-break:break-all" }, message),
67
- h("p", { style: "margin:0 0 10px" }, "\u300C\u91CD\u8BD5\u52A0\u8F7D\u300D\u5728\u5F53\u524D\u9875\u9762\u91CD\u5EFA\u6302\u8F7D\uFF1B\u82E5\u6D4F\u89C8\u5668\u5DF2\u7F13\u5B58\u5931\u8D25\u7684\u6A21\u5757\uFF0C\u8BF7\u7528\u300C\u5237\u65B0\u9875\u9762\u91CD\u8BD5\u300D\u2014\u2014\u5B83\u4F1A\u6574\u9875\u5237\u65B0\uFF08\u4FDD\u7559\u5F53\u524D\u5730\u5740\uFF09\uFF0C\u672A\u4FDD\u5B58\u7684\u9875\u9762\u72B6\u6001\u4F1A\u4E22\u5931\u3002"),
68
- h("div", { style: "margin:0" }, [
69
- props.retry ? h("button", {
70
- key: "retry",
71
- style: BUTTON_STYLE,
72
- type: "button",
73
- "data-fulgurjs-retry": "",
74
- onClick: () => props.retry?.()
75
- }, "\u91CD\u8BD5\u52A0\u8F7D") : null,
76
- h("button", {
77
- key: "reload",
78
- style: SECONDARY_BUTTON_STYLE,
79
- type: "button",
80
- "data-fulgurjs-reload": "",
81
- onClick: reloadPage
82
- }, "\u5237\u65B0\u9875\u9762\u91CD\u8BD5")
83
- ])
84
- ]);
85
- };
86
- }
87
- });
88
- function createVueBridgeAppWithLoader(loadRemote) {
89
- return function createVueBridgeApp(spec, options = {}) {
90
- assertBridgeOptions(`createVueBridgeApp("${spec}")`, options);
91
- const componentName = "FulgurjsBridge_" + spec.replace(/[^A-Za-z0-9_-]/g, "_");
92
- return defineComponent({
93
- name: componentName,
94
- // 多根组件:宿主传入的 class/style 等不自动继承(v1 不提供样式透传,外观由宿主外层元素控制)
95
- inheritAttrs: false,
96
- props: {
97
- appProps: { type: Object, required: false, default: void 0 },
98
- // 桥接控制参数:undefined(不启用受控会话)/ null(登出态)/ 非空字符串(登录代次)
99
- sessionKey: { type: null, required: false, default: void 0 },
100
- // URL 同步控制通道(独立于 appProps/Context;省略 = 原 memory 模式)
101
- routing: { type: Object, required: false, default: void 0 }
102
- },
103
- setup(props) {
104
- const status = ref("idle");
105
- const error = shallowRef(void 0);
106
- const container = ref(null);
107
- let generation = 0;
108
- let contract;
109
- let containerBlocked = false;
110
- let acquiredSession;
111
- let channel;
112
- let genAbort;
113
- const releaseAcquired = () => {
114
- if (acquiredSession !== void 0) {
115
- releaseBridgeSession(acquiredSession);
116
- acquiredSession = void 0;
117
- }
118
- };
119
- const invalidate = () => {
120
- if (containerBlocked) return false;
121
- generation++;
122
- const el = container.value;
123
- releaseAcquired();
124
- genAbort?.abort();
125
- genAbort = void 0;
126
- channel?.dispose();
127
- channel = void 0;
128
- if (contract && el) {
129
- const c = contract;
130
- contract = void 0;
131
- try {
132
- c.unmount(el);
133
- } catch (e) {
134
- const err = bridgeHostError("unmount", spec, e);
135
- containerBlocked = true;
136
- console.error("[fulgurjs] \u6865\u63A5\u5E94\u7528\u5378\u8F7D\u5931\u8D25\uFF0C\u8BE5\u5BB9\u5668\u5DF2\u5C01\u9501\uFF08\u540C\u9875\u53EA\u80FD\u5237\u65B0\u6062\u590D\uFF09\uFF1A", err);
137
- error.value = err;
138
- status.value = "error";
139
- return false;
140
- }
141
- }
142
- return true;
143
- };
144
- const run = async (myGeneration) => {
145
- const el = container.value;
146
- if (!el) return;
147
- const sk = props.sessionKey;
148
- status.value = "pending";
149
- error.value = void 0;
150
- if (sk === null) {
151
- status.value = "idle";
152
- return;
153
- }
154
- try {
155
- assertControlledSessionKey(spec, sk);
156
- const controlled = typeof sk === "string" ? sk : void 0;
157
- if (controlled !== void 0 && controlled !== acquiredSession) {
158
- releaseAcquired();
159
- acquireBridgeSession(spec, controlled);
160
- acquiredSession = controlled;
161
- }
162
- const resolution = resolveBridgeContext(spec, controlled, options.getContext);
163
- if (resolution.provide) provideAppContext(resolution.provide);
164
- const load = loadRemote(spec, { retries: options.retries });
165
- const mod = options.timeout !== void 0 ? await withBridgeTimeout(load, options.timeout, spec) : await load;
166
- if (myGeneration !== generation) return;
167
- contract = assertBridgeContract(spec, mod);
168
- const appPropsSource = props.appProps ? toRaw(props.appProps) : void 0;
169
- genAbort = new AbortController();
170
- let mountOptions = { signal: genAbort.signal };
171
- if (props.routing) {
172
- assertBridgeRoutingProtocolSpec(spec, contract);
173
- const navigation = props.routing.navigation;
174
- const latestLoc = navigation.getLocation();
175
- if (myGeneration !== generation) return;
176
- channel = new RoutingChannel(`bridge-vue:${spec}:${myGeneration}`, props.routing.basePath, navigation, spec);
177
- mountOptions = { signal: genAbort.signal, routing: channel };
178
- void latestLoc;
179
- }
180
- try {
181
- await contract.mount(el, { ...appPropsSource ?? {} }, mountOptions);
182
- } catch (e) {
183
- throw bridgeHostError("mount", spec, e);
184
- }
185
- if (myGeneration !== generation) return;
186
- status.value = "ready";
187
- } catch (e) {
188
- if (myGeneration !== generation) return;
189
- error.value = e;
190
- status.value = "error";
191
- }
192
- };
193
- const start = () => {
194
- const ok = invalidate();
195
- if (!ok) return;
196
- const myGeneration = generation;
197
- void run(myGeneration);
198
- };
199
- const retry = () => {
200
- start();
201
- };
202
- onMounted(() => {
203
- const myGeneration = generation;
204
- void run(myGeneration);
205
- });
206
- watch(() => props.sessionKey, () => {
207
- start();
208
- });
209
- watch(() => routingKey(props.routing), (after, before) => {
210
- if (after !== before) start();
211
- });
212
- onDeactivated(() => {
213
- channel?.setActive(false);
214
- });
215
- onActivated(() => {
216
- channel?.setActive(true);
217
- });
218
- onBeforeUnmount(() => {
219
- invalidate();
220
- });
221
- return () => {
222
- const children = [];
223
- if (status.value === "pending" && options.loadingComponent) {
224
- children.push(h(options.loadingComponent, { key: "loading" }));
225
- }
226
- if (status.value === "error") {
227
- const err = error.value;
228
- if (options.errorComponent) {
229
- children.push(h(options.errorComponent, { key: "error", error: err }));
230
- } else {
231
- children.push(h(BridgeErrorPlaceholder, { key: "error", error: err, retry: containerBlocked ? void 0 : retry }));
232
- }
233
- }
234
- children.push(h("div", {
235
- key: "bridge-root",
236
- ref: container,
237
- "data-fulgurjs-bridge-root": spec,
238
- "data-fulgurjs-bridge-status": status.value
239
- }));
240
- return children;
241
- };
242
- }
243
- });
244
- };
245
- }
246
-
247
- export {
248
- createVueBridgeAppWithLoader
249
- };
@@ -1,207 +0,0 @@
1
- import {
2
- RoutingChannel,
3
- acquireBridgeSession,
4
- assertBridgeContract,
5
- assertBridgeOptions,
6
- assertBridgeRoutingProtocol,
7
- assertControlledSessionKey,
8
- bridgeHostError,
9
- provideAppContext,
10
- releaseBridgeSession,
11
- resolveBridgeContext,
12
- withBridgeTimeout
13
- } from "./chunk-GLASM5EX.js";
14
-
15
- // src/bridge-host-react.ts
16
- import {
17
- createElement,
18
- Fragment,
19
- useEffect,
20
- useRef,
21
- useState
22
- } from "react";
23
- function routingKey(routing) {
24
- if (!routing) return void 0;
25
- return routing.basePath + "|" + String(routing.navigation && typeof routing.navigation.navigate === "function");
26
- }
27
- var ERROR_STYLE = {
28
- padding: "16px",
29
- border: "1px solid #fde2e2",
30
- borderRadius: "4px",
31
- background: "#fef0f0",
32
- color: "#c45656",
33
- fontSize: "13px",
34
- lineHeight: "1.6",
35
- boxSizing: "border-box"
36
- };
37
- var MESSAGE_STYLE = { margin: "0 0 8px", wordBreak: "break-all" };
38
- var BUTTON_STYLE = {
39
- padding: "4px 14px",
40
- marginRight: "8px",
41
- border: "1px solid #c45656",
42
- borderRadius: "4px",
43
- background: "#c45656",
44
- color: "#fff",
45
- fontSize: "13px",
46
- cursor: "pointer"
47
- };
48
- var SECONDARY_BUTTON_STYLE = {
49
- padding: "4px 14px",
50
- border: "1px solid #c45656",
51
- borderRadius: "4px",
52
- background: "#fff",
53
- color: "#c45656",
54
- fontSize: "13px",
55
- cursor: "pointer"
56
- };
57
- function DefaultBridgeErrorView({ error, retry, blocked }) {
58
- const err = error;
59
- const code = err?.code ?? "UNKNOWN";
60
- const message = err?.message ?? String(error ?? "unknown error");
61
- return createElement("div", { style: ERROR_STYLE, "data-fulgurjs-error": code }, [
62
- createElement("p", { key: "t", style: { margin: "0 0 4px", fontWeight: 600 } }, `\u6865\u63A5\u5E94\u7528\u52A0\u8F7D\u5931\u8D25\uFF08\u9519\u8BEF\u7801 ${code}\uFF09`),
63
- createElement("p", { key: "m", style: MESSAGE_STYLE }, message),
64
- createElement(
65
- "p",
66
- { key: "n", style: { margin: "0 0 10px" } },
67
- blocked ? "\u8BE5\u5BB9\u5668\u5DF2\u5C01\u9501\uFF08\u540C\u9875\u65E0\u6CD5\u5B89\u5168\u91CD\u6302\uFF09\uFF0C\u53EA\u80FD\u6574\u9875\u5237\u65B0\u6062\u590D\u2014\u2014\u70B9\u51FB\u300C\u5237\u65B0\u9875\u9762\u91CD\u8BD5\u300D\u4F1A\u91CD\u65B0\u52A0\u8F7D\u9875\u9762\uFF08\u4FDD\u7559\u5F53\u524D\u5730\u5740\uFF09\uFF0C\u672A\u4FDD\u5B58\u7684\u9875\u9762\u72B6\u6001\u4F1A\u4E22\u5931\u3002" : "\u300C\u91CD\u8BD5\u52A0\u8F7D\u300D\u5728\u5F53\u524D\u9875\u9762\u91CD\u5EFA\u6302\u8F7D\uFF1B\u82E5\u6D4F\u89C8\u5668\u5DF2\u7F13\u5B58\u5931\u8D25\u7684\u6A21\u5757\uFF0C\u8BF7\u7528\u300C\u5237\u65B0\u9875\u9762\u91CD\u8BD5\u300D\u2014\u2014\u5B83\u4F1A\u6574\u9875\u5237\u65B0\uFF08\u4FDD\u7559\u5F53\u524D\u5730\u5740\uFF09\uFF0C\u672A\u4FDD\u5B58\u7684\u9875\u9762\u72B6\u6001\u4F1A\u4E22\u5931\u3002"
68
- ),
69
- blocked ? null : createElement("button", { key: "r", type: "button", style: BUTTON_STYLE, "data-fulgurjs-retry": "", onClick: retry }, "\u91CD\u8BD5\u52A0\u8F7D"),
70
- createElement("button", {
71
- key: "rl",
72
- type: "button",
73
- style: SECONDARY_BUTTON_STYLE,
74
- "data-fulgurjs-reload": "",
75
- onClick: () => window.location.reload()
76
- }, "\u5237\u65B0\u9875\u9762\u91CD\u8BD5")
77
- ]);
78
- }
79
- function renderBridgeErrorNode(errorOpt, error, retry, blocked) {
80
- if (typeof errorOpt === "function") return errorOpt(error, retry);
81
- if (errorOpt !== void 0) return errorOpt;
82
- return createElement(DefaultBridgeErrorView, { error, retry, blocked });
83
- }
84
- function createReactBridgeAppWithLoader(loadRemote) {
85
- return function createReactBridgeApp(spec, options = {}) {
86
- assertBridgeOptions(`createReactBridgeApp("${spec}")`, options);
87
- const displayName = "FulgurjsBridge_" + spec.replace(/[^A-Za-z0-9_-]/g, "_");
88
- function BridgeHost(props) {
89
- const [status, setStatus] = useState("idle");
90
- const [error, setError] = useState(void 0);
91
- const [attempt, setAttempt] = useState(0);
92
- const containerRef = useRef(null);
93
- const generationRef = useRef(0);
94
- const contractRef = useRef(void 0);
95
- const acquiredRef = useRef(void 0);
96
- const blockedRef = useRef(false);
97
- const channelRef = useRef(void 0);
98
- const abortRef = useRef(void 0);
99
- const latest = useRef(props);
100
- latest.current = props;
101
- useEffect(() => {
102
- if (blockedRef.current) return;
103
- const myGen = ++generationRef.current;
104
- const el = containerRef.current;
105
- const release = () => {
106
- if (acquiredRef.current !== void 0) {
107
- releaseBridgeSession(acquiredRef.current);
108
- acquiredRef.current = void 0;
109
- }
110
- };
111
- const disposeChannel = () => {
112
- channelRef.current?.dispose();
113
- channelRef.current = void 0;
114
- abortRef.current?.abort();
115
- abortRef.current = void 0;
116
- };
117
- const run = async () => {
118
- if (!el) return;
119
- const sk = latest.current.sessionKey;
120
- setStatus("pending");
121
- setError(void 0);
122
- if (sk === null) {
123
- setStatus("idle");
124
- return;
125
- }
126
- try {
127
- assertControlledSessionKey(spec, sk);
128
- const controlled = typeof sk === "string" ? sk : void 0;
129
- if (controlled !== void 0 && controlled !== acquiredRef.current) {
130
- release();
131
- acquireBridgeSession(spec, controlled);
132
- acquiredRef.current = controlled;
133
- }
134
- const resolution = resolveBridgeContext(spec, controlled, options.getContext);
135
- if (resolution.provide) provideAppContext(resolution.provide);
136
- const load = loadRemote(spec, { retries: options.retries });
137
- const mod = options.timeout !== void 0 ? await withBridgeTimeout(load, options.timeout, spec) : await load;
138
- if (generationRef.current !== myGen) return;
139
- const contract = assertBridgeContract(spec, mod);
140
- contractRef.current = contract;
141
- abortRef.current = new AbortController();
142
- let mountOptions = { signal: abortRef.current.signal };
143
- const routing = latest.current.routing;
144
- if (routing) {
145
- assertBridgeRoutingProtocol(spec, contract);
146
- if (generationRef.current !== myGen) return;
147
- channelRef.current = new RoutingChannel(`bridge-react:${spec}:${myGen}`, routing.basePath, routing.navigation, spec);
148
- mountOptions = { signal: abortRef.current.signal, routing: channelRef.current };
149
- }
150
- try {
151
- await contract.mount(el, { ...latest.current.appProps ?? {} }, mountOptions);
152
- } catch (mountError) {
153
- throw bridgeHostError("mount", spec, mountError);
154
- }
155
- if (generationRef.current !== myGen) return;
156
- setStatus("ready");
157
- } catch (e) {
158
- if (generationRef.current !== myGen) return;
159
- setError(e);
160
- setStatus("error");
161
- }
162
- };
163
- void run();
164
- return () => {
165
- generationRef.current++;
166
- release();
167
- disposeChannel();
168
- const c = contractRef.current;
169
- contractRef.current = void 0;
170
- if (c && el) {
171
- try {
172
- c.unmount(el);
173
- } catch (e) {
174
- const err = bridgeHostError("unmount", spec, e);
175
- console.error("[fulgurjs] \u6865\u63A5\u5E94\u7528\u5378\u8F7D\u5931\u8D25\uFF1A", err);
176
- blockedRef.current = true;
177
- setError(err);
178
- setStatus("error");
179
- }
180
- }
181
- };
182
- }, [props.sessionKey, attempt, routingKey(latest.current.routing)]);
183
- const retry = () => setAttempt((a) => a + 1);
184
- const children = [];
185
- if (status === "pending" && options.fallback !== void 0) {
186
- children.push(createElement(Fragment, { key: "loading" }, options.fallback));
187
- }
188
- if (status === "error") {
189
- children.push(createElement(Fragment, { key: "error" }, renderBridgeErrorNode(options.error, error, retry, blockedRef.current)));
190
- }
191
- children.push(createElement("div", {
192
- key: "bridge-root",
193
- ref: containerRef,
194
- "data-fulgurjs-bridge-root": spec,
195
- "data-fulgurjs-bridge-status": status
196
- }));
197
- return createElement(Fragment, null, children);
198
- }
199
- ;
200
- BridgeHost.displayName = displayName;
201
- return BridgeHost;
202
- };
203
- }
204
-
205
- export {
206
- createReactBridgeAppWithLoader
207
- };