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

feat(gatsby): use production React for dev-ssr when CI=true #28728

Merged
merged 3 commits into from
Dec 29, 2020

Conversation

KyleAMathews
Copy link
Contributor

We don't need React's dev hints & we want SSR to be as fast as possible on CI

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Dec 21, 2020
@ascorbic
Copy link
Contributor

Could this mean that we miss errors, as we're testing something different from users?

@pieh
Copy link
Contributor

pieh commented Dec 22, 2020

Could this mean that we miss errors, as we're testing something different from users?

Probably will not miss errors (tho wording might be different), but warnings on CI wouldn't show, but it doesn't seem like we are testing for those right now.

If there are worries about using generic check testing if we are in CI - maybe this should not care about CI env and instead should be setting for DEV_SSR (wether to use prod or dev react / react-dom/server)? GATSBY_DEV_SSR_USE_PROD_REACT (or something like that)?

@KyleAMathews
Copy link
Contributor Author

@ascorbic this isn't for testing — it's for people running preview servers w/ gatsby develop — there we're assuming people aren't going to be looking at SSR warnings anyways and we want the SSR to be as fast as possible. The dev versions of React are for development which is what we run on people's actual machines.

@ascorbic
Copy link
Contributor

We could check if we're running through Cypress, which is what I'm concerned about.

@pieh
Copy link
Contributor

pieh commented Dec 22, 2020

We could check if we're running through Cypress, which is what I'm concerned about.

Just to be clear - this is for SSR not browser bundle. At the compile time we also have no ability to know if we will run through cypress. We can add some toggle to disable using Prod react for dev SSR for our tests, but so far we don't have any tests for dev ssr that would actually check for warnings (thought we should add some at some point)

@pieh pieh added topic: ssr and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Dec 29, 2020
@pieh
Copy link
Contributor

pieh commented Dec 29, 2020

Even when using externals I found cases when dev version is used - it's when other externals import webpack (

const externalList = [
`@reach/router/lib/history`,
`@reach/router`,
`common-tags`,
`crypto`,
`debug`,
`fs`,
`https`,
`http`,
`lodash`,
`path`,
`semver`,
/^lodash\//,
`zlib`,
]
// Packages we want to externalize because meant to be user-provided
const userExternalList = [`react-helmet`, `react`, /^react-dom\//]
)

In particular @reach/router caused this (I added console.trace() to check), but react-helmet would be another case for it I assume.

Unless we make those not externals anymore I don't see a way to address it without hooking into node.js module loading and making overwrites there too (but that seem messy ...).

In any case - it doesn't seem to cause problems in my testing. The fact remains that it will load react module twice (dev and prod) and it will use dev react for some thing and prod for most of things

@pieh
Copy link
Contributor

pieh commented Dec 29, 2020

To add to above - funnily enough - react-dom also import react, so react-dom being externals is one of things that cause to use dev version of react :(

Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

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

Let's get this in as-is. Main benefit is from using prod version of react-dom/server renderToString - we possibly can squeeze more - but this is good enough for now

@KyleAMathews KyleAMathews merged commit bd6b899 into master Dec 29, 2020
@KyleAMathews KyleAMathews deleted the prod-dev-html branch December 29, 2020 20:17
@vladar vladar added the bot: merge on green Gatsbot will merge these PRs automatically when all tests passes label Dec 29, 2020
vladar pushed a commit that referenced this pull request Dec 29, 2020
* feat(gatsby): use production React for dev-ssr when CI=true

* Use @pieh's suggestion for switching to the prod versions of React/ReactDOM

* Don't need this now

(cherry picked from commit bd6b899)
vladar pushed a commit that referenced this pull request Dec 29, 2020
…28792)

* feat(gatsby): use production React for dev-ssr when CI=true

* Use @pieh's suggestion for switching to the prod versions of React/ReactDOM

* Don't need this now

(cherry picked from commit bd6b899)

Co-authored-by: Kyle Mathews <mathews.kyle@gmail.com>
@vladar
Copy link
Contributor

vladar commented Dec 29, 2020

Published in gatsby@2.29.3

@LekoArts LekoArts added the topic: DX Developer Experience (e.g. Fast Refresh, i18n, SSR, page creation, starters) label May 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: merge on green Gatsbot will merge these PRs automatically when all tests passes topic: DX Developer Experience (e.g. Fast Refresh, i18n, SSR, page creation, starters)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants