From 26447d5a99302cf018103ea02da699762d19fe2b Mon Sep 17 00:00:00 2001 From: Zack Jackson <25274700+ScriptedAlchemy@users.noreply.github.com> Date: Sun, 28 Jun 2026 23:48:02 +0000 Subject: [PATCH] perf: enable lazy compilation by default --- .changeset/default-lazy-compilation.md | 5 +++++ src/index.ts | 11 +++++++---- src/types.ts | 3 ++- tests/index.test.ts | 10 +++++++++- 4 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 .changeset/default-lazy-compilation.md diff --git a/.changeset/default-lazy-compilation.md b/.changeset/default-lazy-compilation.md new file mode 100644 index 00000000..08b07216 --- /dev/null +++ b/.changeset/default-lazy-compilation.md @@ -0,0 +1,5 @@ +--- +"rsbuild-plugin-react-router": patch +--- + +Enable guarded Rsbuild lazy compilation by default during development. Pass `lazyCompilation: false` to keep the previous eager compilation behavior. diff --git a/src/index.ts b/src/index.ts index 105a405e..f157388b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -143,6 +143,7 @@ export const pluginReactRouter = ( async setup(api) { const defaultOptions = { customServer: false, + lazyCompilation: true, serverOutput: 'module' as const, }; @@ -767,10 +768,12 @@ export const pluginReactRouter = ( serverBundleEntries, }); - const configuredLazyCompilation = - pluginOptions.lazyCompilation === undefined - ? config.dev?.lazyCompilation - : pluginOptions.lazyCompilation; + const configuredLazyCompilation = Object.prototype.hasOwnProperty.call( + options, + 'lazyCompilation' + ) + ? pluginOptions.lazyCompilation + : (config.dev?.lazyCompilation ?? pluginOptions.lazyCompilation); const guardedLazyCompilation = guardReactRouterLazyCompilation({ lazyCompilation: configuredLazyCompilation, entryClientPath: finalEntryClientPath, diff --git a/src/types.ts b/src/types.ts index 5d2fe1c6..727ad33f 100644 --- a/src/types.ts +++ b/src/types.ts @@ -32,7 +32,8 @@ export type PluginOptions = { /** * Rsbuild dev-only lazy compilation behavior. - * @default false + * Pass `false` to disable. + * @default true */ lazyCompilation?: NonNullable['lazyCompilation']; diff --git a/tests/index.test.ts b/tests/index.test.ts index c8cfe4b9..4e3ed92d 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -31,7 +31,15 @@ describe('pluginReactRouter', () => { expect(config.dev.hmr).toBe(true); expect(config.dev.liveReload).toBe(true); expect(config.dev.writeToDisk).toBe(true); - expect(config.dev.lazyCompilation).toBeUndefined(); + expect(config.dev.lazyCompilation).toMatchObject({ + entries: true, + imports: true, + }); + expect( + config.dev.lazyCompilation.test({ + resource: `${process.cwd()}/app/entry.client.tsx`, + }) + ).toBe(false); }); it('adds the committed custom-server build entry only in development', async () => {