Skip to content

Commit 0ecbe48

Browse files
committed
fix(reactant-share): fix router lastRoutedTimestamp issue
1 parent 82b97ab commit 0ecbe48

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

packages/reactant-share/src/modules/router.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import type { ISharedAppOptions } from '../interfaces';
3333
import { PortDetector } from './portDetector';
3434
import { delegate } from '../delegate';
3535
import { fork } from '../fork';
36+
import { isSharedWorker } from '../utils';
3637

3738
export {
3839
createBrowserHistory,
@@ -380,7 +381,7 @@ class ReactantRouter extends BaseReactantRouter {
380381
/**
381382
* The timestamp of the last routing.
382383
*/
383-
lastRoutedTimestamp = Date.now();
384+
lastRoutedTimestamp = isSharedWorker ? 0 : Date.now();
384385

385386
protected _changeRoutingOnSever(
386387
name: string,

packages/reactant-share/src/server.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import { PortDetector } from './modules/portDetector';
1414
import { PatchesChecker } from './modules/patchesChecker';
1515
import { applyMethod } from './applyMethod';
16+
import { isSharedWorker } from './utils';
1617

1718
export const handleServer = ({
1819
app,
@@ -32,9 +33,7 @@ export const handleServer = ({
3233
const patchesChecker: PatchesChecker | null = enablePatchesChecker
3334
? container.get(PatchesChecker)
3435
: null;
35-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
36-
// @ts-ignore
37-
if (globalThis.SharedWorkerGlobalScope) {
36+
if (isSharedWorker) {
3837
let executed = false;
3938
// before any other event, it should be connected with the first client
4039
globalThis.addEventListener('connect', () => {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
export const createId = () => Math.random().toString(36).slice(2);
2+
3+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
4+
// @ts-ignore
5+
export const isSharedWorker = !!globalThis.SharedWorkerGlobalScope;

0 commit comments

Comments
 (0)