fix: notify all listeners on page pop to ensure consistent state updates - #2312
Open
dipakp2726 wants to merge 1 commit into
Open
fix: notify all listeners on page pop to ensure consistent state updates#2312dipakp2726 wants to merge 1 commit into
dipakp2726 wants to merge 1 commit into
Conversation
Author
|
https://github.com/dipakp2726/auto_route_url_not_updating_on_pop_reproduce/tree/fix/url-not-updating-on-pop-with-path-params |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2311
Issue
In v9, onPopPage called removeRoute() → _removeRoute() → notifyAll(forceUrlRebuild: true),
which:
In v10+, onPopPage was refactored to:
void onPopPage(AutoRoutePage<Object?> page) {
if (!_pages.remove(page)) return;
_updateSharedPathData(includeAncestors: true);
if (isRouteDataActive(page.routeData)) {
navigationHistory.rebuildUrl();
}
}
This has two problems:
depending on route changes (like bottom nav visibility) doesn't rebuild.
RouteMatch against current URL state segments using RouteMatch.==. This equality check includes
params, stringMatch, key, etc. With path parameters (e.g., /patients/:id), the match object from
the popped page may not compare equal to the stale URL state segment, causing rebuildUrl() to
be skipped entirely.
Fix
Replace the conditional rebuildUrl() with notifyAll(forceUrlRebuild: true), restoring the v9
behavior:
void onPopPage(AutoRoutePage<Object?> page) {
if (!_pages.remove(page)) return;
_updateSharedPathData(includeAncestors: true);
notifyAll(forceUrlRebuild: true);
}
notifyAll(forceUrlRebuild: true) handles both missing pieces: