Repository navigation
fix: state updates detection on history back/forward - #405
Conversation
🦋 Changeset detectedLatest commit: 82f8035 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
I see what you are trying to do but could this already be handled by the current popstate event? I'm gathering this is related to that we don't have access to the state representation where we wire the events. I'm just looking at: solid-router/src/routers/Router.ts Lines 29 to 38 in 3cd2fef And more specifically: Lines 64 to 77 in 3cd2fef And thinking there should be some way to set the source state properly and ensure that the notifications are working properly. Like the bug seems most likely with our way of telling things have changed rather than sideloading in a second event. |
|
@ryansolid Thanks for your response, and yeah that makes sense. From what I found so far, the source solid-router/src/routers/createRouter.ts Line 35 in 3cd2fef To allow the state change detection, we can set
I went with - createSignal(wrap(config.get()), { equals: (a, b) => a.value === b.value }),
+ createSignal(wrap(config.get()), { equals: false }),The other related logic that skips updates if the Lines 333 to 343 in 3cd2fef I was unsure about resetting error-boundaries and submission here as well, so I just added an + } else {
+ start(() => {
+ intent = "native";
+ setState(state);
+ }).then(() => {
+ intent = undefined;
+ });
}Those two changes solved the state-only detection issue. Please let me know what you think, thanks! |
|
I see.. hmm.. yeah that equality check I guess needs to fail here but I do wonder if this can cause other issues. Shortcuts when trying to navigate to the same route. Probably nothing to sever. We should reset errorboundaries and submissions in this case, because it is a navigation. |
|
@ryansolid I re-added the I also added an object equality comparison utility based on fast-deep-equal to compare the Please let me know what you think. Thanks! |
|
I'm going to play around with this and see if the equal check is important. I'm as concerned with adding more code as I am with JSON.stringify performance. So if we can avoid doing much here. My gut here is if the state reference is different that will be sufficient. It might be aggressive but it is probably fine. Like what would be the point of state if someone was just mutating the same reference. You wouldn't be able to go back and forth, as you already changed it. Could it not just be? |
|
@ryansolid Checking the state reference makes total sense in this case.
Yes, I've update the PR accordingly. Thanks again. |
|
Looks great thanks |
This PR adds an event listener to
popstatechange event to update the router state with the history back/forward events between two routes with the same paths but with different state objects.Currently the changes are only detected by refreshing the page.
Closes #275 and #396