Skip to content

Fix RSC fetcher.load #13709

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

Merged
merged 4 commits into from
May 30, 2025
Merged

Fix RSC fetcher.load #13709

merged 4 commits into from
May 30, 2025

Conversation

markdalgleish
Copy link
Member

No description provided.

Copy link

changeset-bot bot commented May 30, 2025

⚠️ No Changeset found

Latest commit: 6076a1e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@markdalgleish markdalgleish marked this pull request as ready for review May 30, 2025 05:48
@@ -2258,7 +2258,6 @@ export function createRouter(init: RouterInit): Router {
return;
}

let match = getTargetMatch(matches, path);
Copy link
Member Author

@markdalgleish markdalgleish May 30, 2025

Choose a reason for hiding this comment

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

In the fog of war case, this match is completely ignored and is reassigned once route discovery is done. In an RSC world, if the the root route doesn't have a path, this line throws an error even though its result would never have been used.

To fix this, the creation of this match variable is delayed until after route discovery has completed and we know for a fact we have valid matches. This also means we no longer pass it as an argument to handleFetcherLoader and handleFetcherAction.

Comment on lines +2356 to +2364
if (!match.route.action && !match.route.lazy) {
let error = getInternalRouterError(405, {
method: submission.formMethod,
pathname: path,
routeId: routeId,
});
setFetcherError(key, routeId, error, { flushSync });
return;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

The detectAndHandle405Error function has been inlined now that this logic is only needed in a single place.

@markdalgleish markdalgleish merged commit 2352aaa into rsc May 30, 2025
5 checks passed
@markdalgleish markdalgleish deleted the markdalgleish/fetcher-load branch May 30, 2025 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant