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

fix(gatsby): Move "react-dom-server" out of framework chunk #37508

Merged
merged 3 commits into from Jan 24, 2023

Conversation

LekoArts
Copy link
Contributor

@LekoArts LekoArts commented Jan 20, 2023

Description

When one uses gatsby-plugin-image the react-dom-server is included into the framework chunk.

Before:

image

After:

image

Related Issues

[ch60411]

Fixes #37281

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jan 20, 2023
@LekoArts LekoArts added topic: webpack/babel Webpack or babel and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Jan 20, 2023
@@ -26,10 +26,16 @@ import { shouldGenerateEngines } from "./engines-helpers"
import { ROUTES_DIRECTORY } from "../constants"
import { BabelConfigItemsCacheInvalidatorPlugin } from "./babel-loader"
import { PartialHydrationPlugin } from "./webpack/plugins/partial-hydration"
import { satisfiesSemvers } from "./flags"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unused import


const FRAMEWORK_BUNDLES = [`react`, `react-dom`, `scheduler`, `prop-types`]

// This regex ignores nested copies of framework libraries so they're bundled with their issuer
const FRAMEWORK_BUNDLES_REGEX = new RegExp(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moving regex creation to top. Better performance than creating the regex over and over again

`|`
)})[\\\\/]`
),
test: FRAMEWORK_BUNDLES_REGEX,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In develop stage we don't need to change anything, react-dom/server is only relevant for build-javascript stage

Comment on lines 645 to 646
module.rawRequest === `react-dom/server` ||
module.rawRequest.includes(`/react-dom-server`)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I use rawRequest or request? Opinions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@wardpeet do you have an opinion here?

Copy link
Contributor

Choose a reason for hiding this comment

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

rawRequest as that's the actual user's request. If you use request, it's appended with loaders etc which will be harder to match

return false
}

return FRAMEWORK_BUNDLES_REGEX.test(module.nameForCondition())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We seem to use module.identifier() in other places but most often on the internet I've seen people use module.nameForCondition()

Copy link
Contributor

Choose a reason for hiding this comment

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

it doesn't really matter for this use case. nameForCondition returns the resource without any query parts.
https://github.com/webpack/webpack/blob/293e677b355da0d5bc4ddfc97d2afec114912711/lib/NormalModule.js#L375-L380

Copy link
Contributor

Choose a reason for hiding this comment

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

this change brakes gatsby-plugin-preact which assumes that test function is a regex

@LekoArts LekoArts marked this pull request as ready for review January 23, 2023 08:07
return false
}

return FRAMEWORK_BUNDLES_REGEX.test(module.nameForCondition())
Copy link
Contributor

Choose a reason for hiding this comment

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

it doesn't really matter for this use case. nameForCondition returns the resource without any query parts.
https://github.com/webpack/webpack/blob/293e677b355da0d5bc4ddfc97d2afec114912711/lib/NormalModule.js#L375-L380

@LekoArts LekoArts merged commit ab85362 into master Jan 24, 2023
@LekoArts LekoArts deleted the react-dom-server-chunking branch January 24, 2023 07:48
danilobuerger added a commit to danilobuerger/gatsby-plugin-pnpm that referenced this pull request Feb 8, 2023
The framework test was changed in gatsby 5.6 via gatsbyjs/gatsby#37508

Therefor framework.test is no longer of type RegExp and fixFrameworkCache would return early. This resulted in the non-creation of framework-[contenthash].js. Instead the framework was then located in app-[contenthash].js

Since I didn't find a good way to get the framework bundles, I just inlined them from the gatsby repos. They were not changed since 2020 (the creation of the framework chunking). So this seems pretty stable.

Further this now checks for react-dom/server and does not include it in the framework bundle as done in the  main gatsby repos by PR linked above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: webpack/babel Webpack or babel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

framework-[contenthash].js includes react-dom-server when using gatsby-plugin-image
3 participants