mirror of
https://github.com/hansjone/netx.git
synced 2026-10-09 04:20:45 +08:00
fix: collection first-run pending and module tab cross-nav
Defer collection scheduling to BackgroundTasks after commit; claim pending runs atomically with retries. Only handle focus-module broadcasts for the matching moduleId so opening one module does not rewrite other tabs. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
3413d5bf32
commit
fed7f56ad0
5 changed files with 169 additions and 43 deletions
|
|
@ -36,13 +36,18 @@ export function registerModuleWindow(moduleId: string): () => void {
|
|||
/* ignore */
|
||||
}
|
||||
|
||||
return registerBroadcastListener<FocusModuleMessage>(MODULE_CHANNEL, moduleAckKey(moduleId), (data) => {
|
||||
const targetPath = String(data.path || "").trim();
|
||||
if (targetPath && window.location.pathname !== targetPath) {
|
||||
window.location.assign(targetPath);
|
||||
}
|
||||
window.focus();
|
||||
});
|
||||
return registerBroadcastListener<FocusModuleMessage>(
|
||||
MODULE_CHANNEL,
|
||||
moduleAckKey(moduleId),
|
||||
(data) => {
|
||||
const targetPath = String(data.path || "").trim();
|
||||
if (targetPath && window.location.pathname !== targetPath) {
|
||||
window.location.assign(targetPath);
|
||||
}
|
||||
window.focus();
|
||||
},
|
||||
(data) => data.moduleId === moduleId,
|
||||
);
|
||||
}
|
||||
|
||||
export function openOrFocusModule({ moduleId, path }: ModuleWindowSpec): void {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ export function registerBroadcastListener<T extends { requestId: string }>(
|
|||
channelName: string,
|
||||
ackStorageKey: string,
|
||||
onMessage: (data: T) => void,
|
||||
shouldHandle?: (data: T) => boolean,
|
||||
): () => void {
|
||||
if (typeof BroadcastChannel === "undefined") {
|
||||
return () => undefined;
|
||||
|
|
@ -19,6 +20,7 @@ export function registerBroadcastListener<T extends { requestId: string }>(
|
|||
channel.onmessage = (ev: MessageEvent<T>) => {
|
||||
const data = ev.data;
|
||||
if (!data?.requestId) return;
|
||||
if (shouldHandle && !shouldHandle(data)) return;
|
||||
try {
|
||||
sessionStorage.setItem(ackStorageKey, data.requestId);
|
||||
} catch {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue