-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Which project does this relate to?
Router
Describe the bug
A follow-up of PR #6093 - In certain scenarios, head function can still run before loaderData is ready, resulting in incorrect head computation, see an example below.
Your Example Website or App
n/a
Steps to Reproduce the Bug or Issue
Say we have a blog site, and accessing an article requires auth. Let's start with the user being logged out.
- Visit
/article/123, shows "Not found" page content, and a generic title. - Log in, and for the sake of argument, the user is redirected to
/dashboard. - Click browser's "Back" button, i.e. navigate back to
/article/123.
Expected behavior
Now we can see an inconsistent state: the document body shows the article content correctly, but we still get the generic title, instead of the article's title, as we expect to see.
The reason is, the head function, which is supposed to return the article title from its loaderData, runs before the loader function can actually finish, and thus, loaderData is not available at the time of execution. (On the other hand, the article content shows correctly, because Route.useLoaderData() works as expected.)
Screenshots or Videos
No response
Platform
- Router / Start Version: 1.143.7
- OS: macOS
- Browser: Chrome
- Browser Version: 144.0
- Bundler: Vite
- Bundler Version: 7.3.0
Additional context
No response