Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/twelve-dancers-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lynx-js/react-rsbuild-plugin": patch
---

Throw error when `extractStr` is `true` and `chunkSplit.strategy` is not `all-in-one` since extracted string of different entries cannot be safely shared in a common chunk.
9 changes: 9 additions & 0 deletions packages/rspeedy/plugin-react/src/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,15 @@ export function applyEntry(

const rsbuildConfig = api.getRsbuildConfig()

if (
extractStr
&& rsbuildConfig.performance?.chunkSplit?.strategy !== 'all-in-one'
) {
throw new Error(
'`extractStr` is only supported in `all-in-one` chunkSplit strategy',
)
}

chain
.plugin(PLUGIN_NAME_REACT)
.after(PLUGIN_NAME_TEMPLATE)
Expand Down
55 changes: 55 additions & 0 deletions packages/rspeedy/plugin-react/test/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,61 @@ describe('Config', () => {
`)
})

test('performance.chunkSplit.strategy: "split-by-experience" along with extractStr: true', async () => {
const { pluginReactLynx } = await import('../src/pluginReactLynx.js')

let rsbuild = await createRsbuild({
rsbuildConfig: {
plugins: [
pluginReactLynx({
extractStr: true,
}),
pluginStubRspeedyAPI(),
],
performance: {
chunkSplit: {
strategy: 'split-by-experience',
},
},
},
})

await expect(rsbuild.initConfigs()).rejects.toMatchInlineSnapshot(
`[Error: \`extractStr\` is only supported in \`all-in-one\` chunkSplit strategy]`,
)

rsbuild = await createRsbuild({
rsbuildConfig: {
plugins: [
pluginReactLynx({
extractStr: true,
}),
pluginStubRspeedyAPI(),
],
},
})

await rsbuild.initConfigs()

rsbuild = await createRsbuild({
rsbuildConfig: {
plugins: [
pluginReactLynx({
extractStr: true,
}),
pluginStubRspeedyAPI(),
],
performance: {
chunkSplit: {
strategy: 'all-in-one',
},
},
},
})

await rsbuild.initConfigs()
})

test('tools.rspack.optimization.splitChunks: false', async () => {
const { pluginReactLynx } = await import('../src/pluginReactLynx.js')

Expand Down
Loading