react-router icon indicating copy to clipboard operation
react-router copied to clipboard

fix(vite): loadEnv before reading routes

Open RFCreate opened this issue 1 month ago • 9 comments

This PR moves the loadDotEnv function prior to configuring the routes.

Why is this important?

I have another project where routes are dynamically generated based on the value of a VITE_* variable, but when running react-router dev, I always get undefined unless I restart manually.

image

This PR removes the need for restarting manually every time.

RFCreate avatar Oct 13 '25 14:10 RFCreate

🦋 Changeset detected

Latest commit: f9153ce77146a2eec02f4997ef76537eac65192d

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

changeset-bot[bot] avatar Oct 13 '25 14:10 changeset-bot[bot]

Hi @RFCreate,

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[bot] avatar Oct 13 '25 14:10 remix-cla-bot[bot]

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

remix-cla-bot[bot] avatar Oct 13 '25 14:10 remix-cla-bot[bot]

Could you remove the upgrades to Vite in the package.json files? You only need to upgrade with pnpm, because that version selector will include 6.3.0.

timdorr avatar Oct 13 '25 14:10 timdorr

I would rather not touch versions but pnpm keeps resolving Vite to version 6.2.5 which will fail in the integration test.

RFCreate avatar Oct 13 '25 15:10 RFCreate

You can see that with Vite version 6.2.7 (latest in 6.2.x) the variable does not even appear after restarting.

image

@timdorr is there a reason for not moving Vite to ^6.3.0?

RFCreate avatar Oct 14 '25 13:10 RFCreate

No, I was just trying to cut down on noise in the PR so the change is more visible.

timdorr avatar Oct 14 '25 13:10 timdorr

The only thing I could think of is to reorder the commits so that the last two are the important ones.

RFCreate avatar Oct 15 '25 13:10 RFCreate

Had to resolve the merge conflicts.

RFCreate avatar Oct 21 '25 23:10 RFCreate

@brophdawg11 Sorry for the ping, is there something missing?

RFCreate avatar Nov 20 '25 23:11 RFCreate

I added a changeset just in case, apart from that everything is the same.

RFCreate avatar Nov 22 '25 04:11 RFCreate

I rewrote the tests to use the new fixtures and added back in the Vite v5 template. That confirmed that there aren't any breaking changes as part of this PR, so I downgraded the changeset from major to patch.

pcattori avatar Nov 24 '25 19:11 pcattori

Thanks for the help.

RFCreate avatar Nov 24 '25 23:11 RFCreate