From 756adf26c2faa088e8f13896df12d080ec967b46 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Wed, 30 Apr 2025 11:35:26 +0900 Subject: [PATCH 1/2] fix: make react preamble inline script async --- packages/plugin-react-oxc/src/index.ts | 2 +- packages/plugin-react-swc/src/index.ts | 2 +- packages/plugin-react/src/index.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/plugin-react-oxc/src/index.ts b/packages/plugin-react-oxc/src/index.ts index 377d4c04..216d5efa 100644 --- a/packages/plugin-react-oxc/src/index.ts +++ b/packages/plugin-react-oxc/src/index.ts @@ -140,7 +140,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] { return [ { tag: 'script', - attrs: { type: 'module' }, + attrs: { type: 'module', async: 'true' }, children: getPreambleCode(config.server!.config.base), }, ] diff --git a/packages/plugin-react-swc/src/index.ts b/packages/plugin-react-swc/src/index.ts index 8e197588..4c430a1a 100644 --- a/packages/plugin-react-swc/src/index.ts +++ b/packages/plugin-react-swc/src/index.ts @@ -135,7 +135,7 @@ const react = (_options?: Options): PluginOption[] => { transformIndexHtml: (_, config) => [ { tag: 'script', - attrs: { type: 'module' }, + attrs: { type: 'module', async: 'true' }, children: getPreambleCode(config.server!.config.base), }, ], diff --git a/packages/plugin-react/src/index.ts b/packages/plugin-react/src/index.ts index cbaa1604..49caded1 100644 --- a/packages/plugin-react/src/index.ts +++ b/packages/plugin-react/src/index.ts @@ -329,7 +329,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] { return [ { tag: 'script', - attrs: { type: 'module' }, + attrs: { type: 'module', async: 'true' }, children: getPreambleCode(config.server!.config.base), }, ] From 1c00c98d13dee7218f5fd57194ca97a731c9fc67 Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Fri, 30 May 2025 14:39:55 +0900 Subject: [PATCH 2/2] fix: `async: true` not `'true'` --- packages/plugin-react-oxc/src/index.ts | 2 +- packages/plugin-react-swc/src/index.ts | 2 +- packages/plugin-react/src/index.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/plugin-react-oxc/src/index.ts b/packages/plugin-react-oxc/src/index.ts index 70e3ab40..9de91bad 100644 --- a/packages/plugin-react-oxc/src/index.ts +++ b/packages/plugin-react-oxc/src/index.ts @@ -141,7 +141,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] { return [ { tag: 'script', - attrs: { type: 'module', async: 'true' }, + attrs: { type: 'module', async: true }, children: getPreambleCode(config.server!.config.base), }, ] diff --git a/packages/plugin-react-swc/src/index.ts b/packages/plugin-react-swc/src/index.ts index 1364b090..dd1a4dcf 100644 --- a/packages/plugin-react-swc/src/index.ts +++ b/packages/plugin-react-swc/src/index.ts @@ -147,7 +147,7 @@ const react = (_options?: Options): PluginOption[] => { return [ { tag: 'script', - attrs: { type: 'module', async: 'true' }, + attrs: { type: 'module', async: true }, children: getPreambleCode(config.server!.config.base), }, ] diff --git a/packages/plugin-react/src/index.ts b/packages/plugin-react/src/index.ts index 1f773af9..1c3e1aef 100644 --- a/packages/plugin-react/src/index.ts +++ b/packages/plugin-react/src/index.ts @@ -366,7 +366,7 @@ export default function viteReact(opts: Options = {}): PluginOption[] { return [ { tag: 'script', - attrs: { type: 'module', async: 'true' }, + attrs: { type: 'module', async: true }, children: getPreambleCode(config.server!.config.base), }, ]