From 81bcfe2b56ad2bf55801c2532925b60685080905 Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 19 Nov 2026 10:43:05 +0800 Subject: [PATCH 1/3] fix: match scriptRegex independently for each file --- src/index.ts | 5 ++++- test/basic/index.test.ts | 14 +++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 96c4f85..7690a38 100644 --- a/src/index.ts +++ b/src/index.ts @@ -33,7 +33,10 @@ const solidLoader: LoaderDefinition = async function ( const sourceFilename = this.resourcePath; const resourceFilename = options.transformFilename ?? sourceFilename; - if (options.scriptRegex && !options.scriptRegex.test(resourceFilename)) { + if ( + options.scriptRegex && + resourceFilename.search(options.scriptRegex) === -1 + ) { callback(null, source, sourceMap); return; } diff --git a/test/basic/index.test.ts b/test/basic/index.test.ts index db73a77..4f1d9aa 100644 --- a/test/basic/index.test.ts +++ b/test/basic/index.test.ts @@ -13,12 +13,16 @@ for (const compiler of ['native', 'babel']) { test(`renders typed SSR output with ${compiler}`, async () => { const cwd = await mkdtemp(path.join(playground, 'test-temp-')); try { + await writeFile( + path.join(cwd, 'Title.tsx'), + 'export const Title = () =>

Hello

;', + ); await writeFile( path.join(cwd, 'app.tsx'), ` import { renderToString } from '@solidjs/web'; - const title: string = 'Hello'; - export const html = renderToString(() =>

{title}

); + import { Title } from './Title.tsx'; + export const html: string = renderToString(() => ); `, ); await new Promise<void>((resolve, reject) => { @@ -46,7 +50,11 @@ for (const compiler of ['native', 'babel']) { }, { loader: 'solid-loader', - options: { compiler, solid: { generate: 'ssr' } }, + options: { + compiler, + scriptRegex: /\.tsx$/g, + solid: { generate: 'ssr' }, + }, }, ], }, From 1a8bd613bbcaefc1381a4745ab3db6723697db3e Mon Sep 17 00:00:00 2001 From: neverland <chenjiahan.jait@bytedance.com> Date: Thu, 19 Nov 2026 10:47:55 +0800 Subject: [PATCH 2/3] test: cover global scriptRegex in a dedicated build --- test/basic/index.test.ts | 14 +++---------- test/basic/scriptRegex.test.ts | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 test/basic/scriptRegex.test.ts diff --git a/test/basic/index.test.ts b/test/basic/index.test.ts index 4f1d9aa..db73a77 100644 --- a/test/basic/index.test.ts +++ b/test/basic/index.test.ts @@ -13,16 +13,12 @@ for (const compiler of ['native', 'babel']) { test(`renders typed SSR output with ${compiler}`, async () => { const cwd = await mkdtemp(path.join(playground, 'test-temp-')); try { - await writeFile( - path.join(cwd, 'Title.tsx'), - 'export const Title = () => <h1>Hello</h1>;', - ); await writeFile( path.join(cwd, 'app.tsx'), ` import { renderToString } from '@solidjs/web'; - import { Title } from './Title.tsx'; - export const html: string = renderToString(() => <Title />); + const title: string = 'Hello'; + export const html = renderToString(() => <h1>{title}</h1>); `, ); await new Promise<void>((resolve, reject) => { @@ -50,11 +46,7 @@ for (const compiler of ['native', 'babel']) { }, { loader: 'solid-loader', - options: { - compiler, - scriptRegex: /\.tsx$/g, - solid: { generate: 'ssr' }, - }, + options: { compiler, solid: { generate: 'ssr' } }, }, ], }, diff --git a/test/basic/scriptRegex.test.ts b/test/basic/scriptRegex.test.ts new file mode 100644 index 0000000..b3ad9bc --- /dev/null +++ b/test/basic/scriptRegex.test.ts @@ -0,0 +1,36 @@ +import { mkdtemp, rm, writeFile } from 'node:fs/promises'; +import path from 'node:path'; +import { promisify } from 'node:util'; +import { rspack } from '@rspack/core'; +import { expect, test } from '@rstest/playwright'; + +test('compiles consecutive JSX files with a global scriptRegex', async () => { + const playground = path.resolve(import.meta.dirname, '../../playground'); + const cwd = await mkdtemp(path.join(playground, 'test-temp-')); + try { + await writeFile( + path.join(cwd, 'app.jsx'), + "import './view.jsx'; export default <main />;", + ); + await writeFile(path.join(cwd, 'view.jsx'), 'export default <p />;'); + + const stats = await promisify(rspack)({ + context: cwd, + mode: 'development', + entry: './app.jsx', + output: { path: cwd }, + module: { + rules: [ + { + test: /\.jsx$/, + loader: 'solid-loader', + options: { scriptRegex: /\.jsx$/g }, + }, + ], + }, + }); + expect(stats?.toJson({ all: false, errors: true }).errors).toEqual([]); + } finally { + await rm(cwd, { recursive: true, force: true }); + } +}); From efdaddcd0c81cce7404e04e5f9be0052994ae662 Mon Sep 17 00:00:00 2001 From: neverland <chenjiahan.jait@bytedance.com> Date: Thu, 19 Nov 2026 10:54:20 +0800 Subject: [PATCH 3/3] test: remove the scriptRegex regression case --- test/basic/scriptRegex.test.ts | 36 ---------------------------------- 1 file changed, 36 deletions(-) delete mode 100644 test/basic/scriptRegex.test.ts diff --git a/test/basic/scriptRegex.test.ts b/test/basic/scriptRegex.test.ts deleted file mode 100644 index b3ad9bc..0000000 --- a/test/basic/scriptRegex.test.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { mkdtemp, rm, writeFile } from 'node:fs/promises'; -import path from 'node:path'; -import { promisify } from 'node:util'; -import { rspack } from '@rspack/core'; -import { expect, test } from '@rstest/playwright'; - -test('compiles consecutive JSX files with a global scriptRegex', async () => { - const playground = path.resolve(import.meta.dirname, '../../playground'); - const cwd = await mkdtemp(path.join(playground, 'test-temp-')); - try { - await writeFile( - path.join(cwd, 'app.jsx'), - "import './view.jsx'; export default <main />;", - ); - await writeFile(path.join(cwd, 'view.jsx'), 'export default <p />;'); - - const stats = await promisify(rspack)({ - context: cwd, - mode: 'development', - entry: './app.jsx', - output: { path: cwd }, - module: { - rules: [ - { - test: /\.jsx$/, - loader: 'solid-loader', - options: { scriptRegex: /\.jsx$/g }, - }, - ], - }, - }); - expect(stats?.toJson({ all: false, errors: true }).errors).toEqual([]); - } finally { - await rm(cwd, { recursive: true, force: true }); - } -});