Skip to content
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

Define process.env.NODE_ENV in build process. #10553

Merged
merged 1 commit into from
May 11, 2024

Conversation

peterp
Copy link
Contributor

@peterp peterp commented May 9, 2024

This fixes a bug where RSC would complain about the Client using the development version of React whilst the server was using the production version. The reason for this is
that Vite's bundling process it replaces "process.env.NODE_ENV" with the values specified in the define configuration. Supplying this configuration option during the build
process ensures that we're using the same version of React.

image

@peterp peterp requested a review from Tobbe May 9, 2024 18:46
@@ -31,6 +31,9 @@ export async function rscBuildClient(clientEntryFiles: Record<string, string>) {

const clientBuildOutput = await viteBuild({
envFile: false,
define: {
Copy link
Member

Choose a reason for hiding this comment

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

Does having define here, and in the other viteBuild invocations, interfere with what we do in getMergedConfig.ts where we set define: getEnvVarDefinitions()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just checked, and I don't think any of the places where I'm setting define makes use of redwoodPluginVite, but then again I don't think redwoodPluginVite is used at all? (I could be wrong.)

image

Copy link
Member

Choose a reason for hiding this comment

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

It's used by every Redwood App (that has Vite setup, which they all do by default now)

If you look in the kitchen-sink test project inside web/vite.config.ts it imports it as redwood from @redwoodjs/vite.

And then at least rscBuildAnalyze uses that config file by doing configFile: rwPaths.web.viteConfig

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oooh, ok! Let me look into that!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it'll interfere; the only place where I modify, and we include the default config is here:

configFile: rwPaths.web.viteConfig,
, and then NODE_ENV will be replaced appropriately as part of the build process.

@Tobbe Tobbe added this to the RSC milestone May 9, 2024
@Tobbe Tobbe added release:fix This PR is a fix changesets-ok Override the changesets check labels May 9, 2024
@Tobbe Tobbe merged commit fc1959e into main May 11, 2024
50 of 59 checks passed
@Tobbe Tobbe deleted the pp-set-NODE_ENV-in-vite-build-process branch May 11, 2024 08:33
dac09 added a commit that referenced this pull request May 15, 2024
…uth-store

* 'main' of github.com:redwoodjs/redwood:
  chore(router): Add more code comments to analyzeRoutes (#10569)
  RSC: No need to use memo or useMemo in the server router (#10568)
  RSC: getViteConfig in rscWorker (#10567)
  Split RSC and RSA handling in rscWorker (#10565)
  RSC: Extract the fetchRSC function (#10564)
  RSC: Fix TODO regarding SSR in client.ts (#10562)
  Docs: QoL Updates to Contributing.md (#10561)
  Added warning note to not add WebAuthn (#10231)
  fix(rsc): Load all css links to support css with rsc (#10544)
  fix(cli): Add deprecation notice for edgio deployment (#10551)
  Define `process.env.NODE_ENV` in build process. (#10553)
  chore(docs): Update dbAuth and Supabase middleware READMEs (#10552)
  chore(deps): Upgrade React 19 to beta 20240508 (#10560)
  Revert "chore(deps): React beta 20240508 (#10558)" (#10559)
  chore(deps): React beta 20240508 (#10558)
  fix(functions): Fix context variable warning/error (#10556)
  fix(functions): Mock context in function test template (#10555)
  chore(middleware): Format code and comments and fix comment grammar (#10554)
@Josh-Walker-GM Josh-Walker-GM modified the milestones: RSC, v8.0.0 Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changesets-ok Override the changesets check release:fix This PR is a fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants