From 6f8445afabe96a03c015f00b82ce12617a45bd67 Mon Sep 17 00:00:00 2001 From: Claudio Wunder Date: Thu, 8 Oct 2026 19:12:49 +0200 Subject: [PATCH] fix(react): turn off Rolldown's module-level directive warnings Every html build warns once for each dependency module marked `"use client"` (`@node-core/ui-components` and the Radix packages it uses): 34 warnings when building the Node.js docs, the same 17 modules in both the server and the client bundles. Neither Vite nor Rolldown filters them by default. The directive is for React Server Components, which these builds don't use, and Rolldown drops it from bundled modules by design (see https://rolldown.rs/in-depth/directives#other-directives). Its `checks.moduleLevelDirective` option now defaults to off, and a project's own `rolldownOptions.checks` still overrides it. Assisted-by: Claude Opus 5.5 --- .changeset/quiet-use-client-warnings.md | 5 ++++ .../src/html/bundlers/__tests__/vite.test.mjs | 24 +++++++++++++++++++ packages/react/src/html/bundlers/vite.mjs | 9 +++++++ 3 files changed, 38 insertions(+) create mode 100644 .changeset/quiet-use-client-warnings.md diff --git a/.changeset/quiet-use-client-warnings.md b/.changeset/quiet-use-client-warnings.md new file mode 100644 index 00000000..a720e1f2 --- /dev/null +++ b/.changeset/quiet-use-client-warnings.md @@ -0,0 +1,5 @@ +--- +'@doc-kit/generator-react': patch +--- + +Stop the Vite builds from warning about every `"use client"` directive in dependencies diff --git a/packages/react/src/html/bundlers/__tests__/vite.test.mjs b/packages/react/src/html/bundlers/__tests__/vite.test.mjs index 4f15ebe1..676ce4ec 100644 --- a/packages/react/src/html/bundlers/__tests__/vite.test.mjs +++ b/packages/react/src/html/bundlers/__tests__/vite.test.mjs @@ -84,6 +84,30 @@ describe('Vite configuration', () => { assert.strictEqual(config.build.manifest, 'manifest.json'); }); + it("leaves out module-level directive warnings unless they're asked for", () => { + /** + * @param {import('vite').UserConfig} [vite] + */ + const checksFor = vite => + createViteConfig({ + sources: new Map(), + input: {}, + server: false, + outDir: output, + config: getConfig('html'), + vite, + }).build.rolldownOptions.checks; + + assert.deepStrictEqual(checksFor(), { moduleLevelDirective: false }); + + const checks = { moduleLevelDirective: true, eval: false }; + + assert.deepStrictEqual( + checksFor({ build: { rolldownOptions: { checks } } }), + checks + ); + }); + it('keeps the server library self-contained', () => { const vite = { ssr: { diff --git a/packages/react/src/html/bundlers/vite.mjs b/packages/react/src/html/bundlers/vite.mjs index 73e3c004..4b2079cf 100644 --- a/packages/react/src/html/bundlers/vite.mjs +++ b/packages/react/src/html/bundlers/vite.mjs @@ -230,6 +230,15 @@ export const createViteConfig = ({ ...vite.build?.rolldownOptions, input, ...(server ? { external: [] } : {}), + + // Dependencies' `"use client"` directives are for React Server + // Components, which bundling drops and this site doesn't use. See + // https://rolldown.rs/in-depth/directives#other-directives + checks: { + moduleLevelDirective: false, + ...vite.build?.rolldownOptions?.checks, + }, + output: { ...vite.build?.rolldownOptions?.output, format: 'es',