packages icon indicating copy to clipboard operation
packages copied to clipboard

[go_router]: Fix `GoRouter.refresh()` trigger route rebuild/refresh

Open CaoGiaHieu-dev opened this issue 2 months ago • 4 comments

Add _refreshKey to MatchBase and update GoRouter.refresh() logic

This maybe fix: https://github.com/flutter/flutter/issues/175399

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.

CaoGiaHieu-dev avatar Nov 05 '25 03:11 CaoGiaHieu-dev

If the RoutematchList doesn't change, why do we want to force a rebuild in the RouterDelegate? I thought the point to do the refresh is that the redirect would produce a different result

My intention is to update the _refreshKey in RoutematchList to notify the _CustomNavigator since it was only notify when matchList was changed

CaoGiaHieu-dev avatar Nov 07 '25 03:11 CaoGiaHieu-dev

My intention is to update the _refreshKey in RoutematchList to notify the _CustomNavigator

Can you talk more about the use case? why would the navigator want to be notified even though there is no change the the route?

chunhtai avatar Nov 26 '25 17:11 chunhtai

Can you talk more about the use case? why would the navigator want to be notified even though there is no change the the route?

In related issue and in current code. Goruter.refresh() does not trigger the rebuild/refresh of the route because _CustomNavigator is blocked when checking matchList.

In my pr the main purpose is to add _refreshKey to the routes to ensure that every time refresh() is called it will update the value of _refreshKey and make _CustomNavigator notify the builder

I think the confusing thing is that I am using routerDelegate.setNewRoutePath for the refresh() function. This I think does not affect because from what I understand the package is processing based on the key of the route. (please confirm) . What I am trying to do is to update all current routes with the new _refreshKey value

CaoGiaHieu-dev avatar Nov 27 '25 01:11 CaoGiaHieu-dev

I understand what the code is doing. My question is why we want a CustomNavigator rebuild when match list doesn't change. It seems to me your use case is relying on a side affect of custom navigator rebuild, and I am not sure if that is a good thing.

chunhtai avatar Dec 09 '25 20:12 chunhtai