diff --git a/packages/gatsby-plugin-preact/src/__tests__/gatsby-node.js b/packages/gatsby-plugin-preact/src/__tests__/gatsby-node.js index 3ab7bd41fea84..61707a32095bc 100644 --- a/packages/gatsby-plugin-preact/src/__tests__/gatsby-node.js +++ b/packages/gatsby-plugin-preact/src/__tests__/gatsby-node.js @@ -1,8 +1,20 @@ -const path = require(`path`) const { onCreateWebpackConfig, onCreateBabelConfig } = require(`../gatsby-node`) const PreactRefreshPlugin = require(`@prefresh/webpack`) const ReactRefreshWebpackPlugin = require(`@pmmmwh/react-refresh-webpack-plugin`) +const FRAMEWORK_BUNDLES_GATSBY = [ + `react`, + `react-dom`, + `scheduler`, + `prop-types`, +] + +const FRAMEWORK_BUNDLES_REGEX_GATSBY = new RegExp( + `(? { it(`sets the correct webpack config in development`, () => { const getConfig = jest.fn(() => { @@ -53,7 +65,6 @@ describe(`gatsby-plugin-preact`, () => { }) it(`sets the correct webpack config in production`, () => { - const FRAMEWORK_BUNDLES = [`react`, `react-dom`, `scheduler`, `prop-types`] const getConfig = jest.fn(() => { return { optimization: { @@ -65,14 +76,20 @@ describe(`gatsby-plugin-preact`, () => { framework: { chunks: `all`, name: `framework`, - // This regex ignores nested copies of framework libraries so they're bundled with their issuer. - test: new RegExp( - `(? { + if ( + module?.rawRequest === `react-dom/server` || + module?.rawRequest?.includes(`/react-dom-server`) + ) { + return false + } + + return FRAMEWORK_BUNDLES_REGEX_GATSBY.test( + module.nameForCondition() + ) + }, priority: 40, - // Don't let webpack eliminate this chunk (prevents this chunk from becoming a part of the commons chunk) enforce: true, }, }, @@ -121,7 +138,7 @@ describe(`gatsby-plugin-preact`, () => { "enforce": true, "name": "framework", "priority": 40, - "test": [Function], + "test": /\\(\\? { "enforce": true, "name": "framework", "priority": 40, - "test": /\\(\\? - /(? { // Packages like gatsby-plugin-image might import from "react-dom/server". We don't want to include react-dom-server in the framework bundle. // A rawRequest might look like these: