Skip to content

Conversation

joshuaellis
Copy link

@joshuaellis joshuaellis commented Oct 14, 2025

Description

React dedupes CSS files that are identical, which is a good default in the case of vanilla react where multiple components might require the same chunk of css however in react router where the route may mount the css chunk first before lazy loaded components have loaded can cause those lazy loaded components to loose their styles when the page is navigated away from.

To solve this, we add a small hash param to route level CSS in the dev package. I used a hash as opposed to a search param because it doesn't download the same CSS twice but the deduping is no longer happening. We still fetch the CSS on route changes, but this is the same behaviour we have now in react-router so i've assumed this is fine.

I've left the branch on my fork with the failing test displayed in 14415, but otherwise modified it here to be a test to keep long term.

Related issues

Copy link

changeset-bot bot commented Oct 14, 2025

🦋 Changeset detected

Latest commit: 31e26ac

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
@react-router/dev Patch
@react-router/fs-routes Patch
@react-router/remix-routes-option-adapter Patch
create-react-router Patch
react-router Patch
react-router-dom Patch
@react-router/architect Patch
@react-router/cloudflare Patch
@react-router/express Patch
@react-router/node Patch
@react-router/serve Patch

Not sure what this means? Click here to learn what changesets are.

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

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Oct 14, 2025

Hi @joshuaellis,

Welcome, and thank you for contributing to React Router!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at [email protected].

Thanks!

- The Remix team

@joshuaellis joshuaellis changed the base branch from main to dev October 14, 2025 08:24
@joshuaellis joshuaellis changed the base branch from dev to main October 14, 2025 08:25
@joshuaellis joshuaellis changed the base branch from main to dev October 14, 2025 08:28
@joshuaellis joshuaellis force-pushed the fix/css-lazy-load-bug branch 2 times, most recently from 2f46daa to baf33ba Compare October 14, 2025 08:31
@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Oct 14, 2025

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

@joshuaellis joshuaellis force-pushed the fix/css-lazy-load-bug branch from 151ce80 to 37a4218 Compare October 14, 2025 08:36
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.

Route navigation removes CSS files that lazy loaded components are using

2 participants