Skip to content

fix(dev): handle critical CSS with absolute base and Vite Env API #13598

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

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

chr33s
Copy link

@chr33s chr33s commented May 13, 2025

As above, using new URL may not be the best solution, but was the easiest.

Copy link

changeset-bot bot commented May 13, 2025

🦋 Changeset detected

Latest commit: 7cea871

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 May 13, 2025

Hi @chr33s,

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

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented May 13, 2025

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

chr33s added a commit to chr33s/shopflare that referenced this pull request May 13, 2025
@MichaelDeBoey MichaelDeBoey changed the title FIX: @react-router/critical.css handling when vite base is an absolute path fix(dev/vite): fix for absolute vite base path May 13, 2025
@timdorr
Copy link
Member

timdorr commented May 13, 2025

Any chance we could add a test for this?

@chr33s
Copy link
Author

chr33s commented May 14, 2025

@timdorr as requested, refactored the change to a helper function and included tests to cover both relative and absolute vite base paths.

@brophdawg11 brophdawg11 removed their request for review May 14, 2025 14:42
@@ -1576,7 +1576,7 @@ export const reactRouterVitePlugin: ReactRouterVitePlugin = () => {
if (ctx.reactRouterConfig.future.unstable_viteEnvironmentApi) {
viteDevServer.middlewares.use(async (req, res, next) => {
let [reqPathname, reqSearch] = (req.url ?? "").split("?");
if (reqPathname === `${ctx.publicPath}@react-router/critical.css`) {
if (reqPathname === getRelativePathName(`${ctx.publicPath}@react-router/critical.css`)) {
Copy link
Member

@markdalgleish markdalgleish May 14, 2025

Choose a reason for hiding this comment

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

Since this is only used during development, I'm happy to simplify this by simply checking that reqPathname.endsWith("/@react-router/critical.css") and not worrying about the rest of the path.

The /@react-router/ prefix is sufficient for me to treat this as private implementation detail and not worry about clashing with other URLs.

Also, simplifying in this way makes me feel like additional tests are unnecessary.

@markdalgleish markdalgleish changed the title fix(dev/vite): fix for absolute vite base path fix(dev): handle critical CSS with absolute base and Vite Env API May 14, 2025
@chr33s
Copy link
Author

chr33s commented May 15, 2025

@markdalgleish updated as per your comment.

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.

4 participants