Skip to content

Commit 026fdca

Browse files
committed
feat: handle state sync w/ current source changes
1 parent 4a76e7d commit 026fdca

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

src/routers/createRouter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function createRouter(config: {
3232
let ignore = false;
3333
const wrap = (value: string | LocationChange) => (typeof value === "string" ? { value } : value);
3434
const signal = intercept<LocationChange>(
35-
createSignal(wrap(config.get()), { equals: (a, b) => a.value === b.value }),
35+
createSignal(wrap(config.get()), { equals: false }),
3636
undefined,
3737
next => {
3838
!ignore && config.set(next);

src/routing.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,6 @@ export function createRouterContext(
326326
}
327327
};
328328

329-
if (!isServer) {
330-
const syncState = () => setState(window.history.state);
331-
window.addEventListener("popstate", syncState);
332-
onCleanup(() => window.removeEventListener("popstate", syncState));
333-
}
334-
335329
createRenderEffect(() => {
336330
const { value, state } = source();
337331
// Untrack this whole block so `start` doesn't cause Solid's Listener to be preserved
@@ -346,6 +340,13 @@ export function createRouterContext(
346340
}).then(() => {
347341
intent = undefined;
348342
});
343+
} else {
344+
start(() => {
345+
intent = "native";
346+
setState(state);
347+
}).then(() => {
348+
intent = undefined;
349+
});
349350
}
350351
});
351352
});

0 commit comments

Comments
 (0)