Skip to content

fix: server actions should fetch from the router canonicalUrl #80690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

ztanner
Copy link
Member

@ztanner ztanner commented Jun 19, 2025

A test related to navigation + server action handling was frequently flaking in CI (x-ref). When simulating a 20x browser slowdown, it's fairly easy to reproduce the failure case as well.

The failure occurs due to a race where the router will invoke the server action against the page the user was on before the navigation, but after the navigation action has been processed. As a result, the RSC payload associated with the target page gets replaced by the RSC payload returned from the server action. There exists a window of time where window.location.pathname is still referring to the previous URL while routerState.canonicalUrl would have been updated to the new page.

This revealed two things:

  • The behavior being tested here only tests the expected behavior some of the time: when it failed, it meant the action wasn't actually forwarded (not currently addressed by this PR)
  • The router state should be the source of truth when determining the URL to fetch from

Copy link
Member Author

ztanner commented Jun 19, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@@ -898,13 +898,6 @@ describe('app-dir action handling', () => {
.elementByCss(`[href='/delayed-action/${runtime}/other']`)
.click()

// wait for url to change
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was added in 5d4f2de to attempt to de-flake the test but shouldn't be necessary. I also needed to touch this file so that flake detection will run

@ztanner ztanner marked this pull request as ready for review June 19, 2025 17:01
@ztanner ztanner enabled auto-merge (squash) June 19, 2025 17:14
@ztanner ztanner merged commit fc99399 into canary Jun 19, 2025
258 of 262 checks passed
@ztanner ztanner deleted the 06-19-fix_server_actions_should_fetch_from_the_router_canonicalurl branch June 19, 2025 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants