@module-federation/bridge-react 0.0.0-next-20240909101028 → 0.0.0-next-20240911025149
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 +2 -3
- package/dist/index.cjs.js +0 -32
- package/dist/index.d.ts +0 -5
- package/dist/index.es.js +1 -33
- package/package.json +2 -2
- package/src/index.ts +0 -1
- package/src/hooks.tsx +0 -44
package/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
# @module-federation/bridge-react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
3
|
+
## 0.0.0-next-20240911025149
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
- @module-federation/bridge-shared@0.0.0-next-20240909101028
|
|
7
|
+
- @module-federation/bridge-shared@0.0.0-next-20240911025149
|
|
9
8
|
|
|
10
9
|
## 0.6.1
|
|
11
10
|
|
package/dist/index.cjs.js
CHANGED
|
@@ -399,37 +399,5 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
399
399
|
};
|
|
400
400
|
};
|
|
401
401
|
}
|
|
402
|
-
function useBridgeRouteChange(onRouteChange) {
|
|
403
|
-
const previousUrlRef = React.useRef(window.location.pathname);
|
|
404
|
-
React.useEffect(() => {
|
|
405
|
-
const handleRouteChange = () => {
|
|
406
|
-
const currentUrl = window.location.pathname;
|
|
407
|
-
const from = previousUrlRef.current;
|
|
408
|
-
const to = currentUrl;
|
|
409
|
-
if (from !== to) {
|
|
410
|
-
onRouteChange({ from, to });
|
|
411
|
-
previousUrlRef.current = currentUrl;
|
|
412
|
-
}
|
|
413
|
-
};
|
|
414
|
-
const originalPushState = window.history.pushState;
|
|
415
|
-
const originalReplaceState = window.history.replaceState;
|
|
416
|
-
window.history.pushState = function(...args) {
|
|
417
|
-
originalPushState.apply(window.history, args);
|
|
418
|
-
handleRouteChange();
|
|
419
|
-
};
|
|
420
|
-
window.history.replaceState = function(...args) {
|
|
421
|
-
console.log("<<<<< replaceState called >>>>>>>", args);
|
|
422
|
-
originalReplaceState.apply(window.history, args);
|
|
423
|
-
handleRouteChange();
|
|
424
|
-
};
|
|
425
|
-
window.addEventListener("popstate", handleRouteChange);
|
|
426
|
-
return () => {
|
|
427
|
-
window.history.pushState = originalPushState;
|
|
428
|
-
window.history.replaceState = originalReplaceState;
|
|
429
|
-
window.removeEventListener("popstate", handleRouteChange);
|
|
430
|
-
};
|
|
431
|
-
}, [onRouteChange]);
|
|
432
|
-
}
|
|
433
402
|
exports.createBridgeComponent = createBridgeComponent;
|
|
434
403
|
exports.createRemoteComponent = createRemoteComponent;
|
|
435
|
-
exports.useBridgeRouteChange = useBridgeRouteChange;
|
package/dist/index.d.ts
CHANGED
|
@@ -66,9 +66,4 @@ export declare interface RenderFnParams extends ProviderParams {
|
|
|
66
66
|
|
|
67
67
|
declare type RootType = HTMLElement | default_3.Root;
|
|
68
68
|
|
|
69
|
-
export declare function useBridgeRouteChange(onRouteChange: ({ from, to }: {
|
|
70
|
-
from: string;
|
|
71
|
-
to: string;
|
|
72
|
-
}) => void): void;
|
|
73
|
-
|
|
74
69
|
export { }
|
package/dist/index.es.js
CHANGED
|
@@ -380,39 +380,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
380
380
|
};
|
|
381
381
|
};
|
|
382
382
|
}
|
|
383
|
-
function useBridgeRouteChange(onRouteChange) {
|
|
384
|
-
const previousUrlRef = useRef(window.location.pathname);
|
|
385
|
-
useEffect(() => {
|
|
386
|
-
const handleRouteChange = () => {
|
|
387
|
-
const currentUrl = window.location.pathname;
|
|
388
|
-
const from = previousUrlRef.current;
|
|
389
|
-
const to = currentUrl;
|
|
390
|
-
if (from !== to) {
|
|
391
|
-
onRouteChange({ from, to });
|
|
392
|
-
previousUrlRef.current = currentUrl;
|
|
393
|
-
}
|
|
394
|
-
};
|
|
395
|
-
const originalPushState = window.history.pushState;
|
|
396
|
-
const originalReplaceState = window.history.replaceState;
|
|
397
|
-
window.history.pushState = function(...args) {
|
|
398
|
-
originalPushState.apply(window.history, args);
|
|
399
|
-
handleRouteChange();
|
|
400
|
-
};
|
|
401
|
-
window.history.replaceState = function(...args) {
|
|
402
|
-
console.log("<<<<< replaceState called >>>>>>>", args);
|
|
403
|
-
originalReplaceState.apply(window.history, args);
|
|
404
|
-
handleRouteChange();
|
|
405
|
-
};
|
|
406
|
-
window.addEventListener("popstate", handleRouteChange);
|
|
407
|
-
return () => {
|
|
408
|
-
window.history.pushState = originalPushState;
|
|
409
|
-
window.history.replaceState = originalReplaceState;
|
|
410
|
-
window.removeEventListener("popstate", handleRouteChange);
|
|
411
|
-
};
|
|
412
|
-
}, [onRouteChange]);
|
|
413
|
-
}
|
|
414
383
|
export {
|
|
415
384
|
createBridgeComponent,
|
|
416
|
-
createRemoteComponent
|
|
417
|
-
useBridgeRouteChange
|
|
385
|
+
createRemoteComponent
|
|
418
386
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/bridge-react",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20240911025149",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@loadable/component": "^5.16.4",
|
|
37
37
|
"react-error-boundary": "^4.0.13",
|
|
38
|
-
"@module-federation/bridge-shared": "0.0.0-next-
|
|
38
|
+
"@module-federation/bridge-shared": "0.0.0-next-20240911025149"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"react": ">=16.9.0",
|
package/src/index.ts
CHANGED
package/src/hooks.tsx
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { useEffect, useRef } from 'react';
|
|
2
|
-
|
|
3
|
-
function useBridgeRouteChange(
|
|
4
|
-
onRouteChange: ({ from, to }: { from: string; to: string }) => void,
|
|
5
|
-
) {
|
|
6
|
-
const previousUrlRef = useRef(window.location.pathname);
|
|
7
|
-
|
|
8
|
-
useEffect(() => {
|
|
9
|
-
const handleRouteChange = () => {
|
|
10
|
-
const currentUrl = window.location.pathname;
|
|
11
|
-
const from = previousUrlRef.current;
|
|
12
|
-
const to = currentUrl;
|
|
13
|
-
|
|
14
|
-
if (from !== to) {
|
|
15
|
-
onRouteChange({ from, to });
|
|
16
|
-
previousUrlRef.current = currentUrl;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const originalPushState = window.history.pushState;
|
|
21
|
-
const originalReplaceState = window.history.replaceState;
|
|
22
|
-
|
|
23
|
-
window.history.pushState = function (...args) {
|
|
24
|
-
originalPushState.apply(window.history, args);
|
|
25
|
-
handleRouteChange();
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
window.history.replaceState = function (...args) {
|
|
29
|
-
console.log('<<<<< replaceState called >>>>>>>', args);
|
|
30
|
-
originalReplaceState.apply(window.history, args);
|
|
31
|
-
handleRouteChange(); // Manually trigger route change handler
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
window.addEventListener('popstate', handleRouteChange);
|
|
35
|
-
|
|
36
|
-
return () => {
|
|
37
|
-
window.history.pushState = originalPushState;
|
|
38
|
-
window.history.replaceState = originalReplaceState;
|
|
39
|
-
window.removeEventListener('popstate', handleRouteChange);
|
|
40
|
-
};
|
|
41
|
-
}, [onRouteChange]);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export { useBridgeRouteChange };
|