Skip to content

Commit 3b97809

Browse files
authored
Merge pull request #405 from oedotme/main
fix: state updates detection on history back/forward
2 parents 884b8be + 82f8035 commit 3b97809

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

.changeset/lucky-dingos-happen.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/router": patch
3+
---
4+
5+
Fix state updates detection on history back/forward

src/routers/createRouter.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ 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()), {
36+
equals: (a, b) => a.value === b.value && a.state === b.state
37+
}),
3638
undefined,
3739
next => {
3840
!ignore && config.set(next);

src/routing.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -337,17 +337,15 @@ export function createRouterContext(
337337
const { value, state } = source();
338338
// Untrack this whole block so `start` doesn't cause Solid's Listener to be preserved
339339
untrack(() => {
340-
if (value !== reference()) {
341-
start(() => {
342-
intent = "native";
343-
setReference(value);
344-
setState(state);
345-
resetErrorBoundaries();
346-
submissions[1]([]);
347-
}).then(() => {
348-
intent = undefined;
349-
});
350-
}
340+
start(() => {
341+
intent = "native";
342+
if (value !== reference()) setReference(value);
343+
setState(state);
344+
resetErrorBoundaries();
345+
submissions[1]([]);
346+
}).then(() => {
347+
intent = undefined;
348+
});
351349
});
352350
});
353351

0 commit comments

Comments
 (0)