Skip to content

fix(html): keep module scripts with src and inline content in build - #23421

Open
2234839 wants to merge 2 commits into
vitejs:mainfrom
2234839:fix/module-script-with-src-and-content
Open

fix(html): keep module scripts with src and inline content in build#23421
2234839 wants to merge 2 commits into
vitejs:mainfrom
2234839:fix/module-script-with-src-and-content

Conversation

@2234839

@2234839 2234839 commented Sep 3, 2026

Copy link
Copy Markdown

Per the HTML spec, a script with both a src attribute and inline content must only execute the external script and ignore the content.

In buildHtmlPlugin, when a module script had a src that was excluded from bundling (external URL, data URL) or referenced a public file, and the tag also contained text (e.g. a newline), the code fell into the inline-module branch: the whitespace was treated as an inline module and the whole script tag was removed, silently dropping the external script. The dev server already handles this correctly by checking src first.

Only treat the content as an inline module when the script has no src at all.

Per the HTML spec, a script with both a `src` attribute and inline
content must only execute the external script and ignore the content.

In buildHtmlPlugin, when a module script had a src that was excluded
from bundling (external URL, data URL) or referenced a public file,
and the tag also contained text (e.g. a newline), the code fell into
the inline-module branch: the whitespace was treated as an inline
module and the whole script tag was removed, silently dropping the
external script. The dev server already handles this correctly by
checking `src` first.

Only treat the content as an inline module when the script has no src
at all.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant