Skip to content

feat(html): implement asset URL rewriting for <iframe srcdoc> in HTML#21226

Merged
alexander-akait merged 17 commits into
webpack:mainfrom
bjohansebas:feat/html-iframe-srcdoc
Jun 23, 2026
Merged

feat(html): implement asset URL rewriting for <iframe srcdoc> in HTML#21226
alexander-akait merged 17 commits into
webpack:mainfrom
bjohansebas:feat/html-iframe-srcdoc

Conversation

@bjohansebas

Copy link
Copy Markdown
Member

Summary

What kind of change does this PR introduce?

Did you add tests for your changes?

Does this PR introduce a breaking change?

If relevant, what needs to be documented once your changes are merged or what have you already documented?

Use of AI

@changeset-bot

changeset-bot Bot commented Jun 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 06bb04b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
webpack Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.81%. Comparing base (ecc00c0) to head (06bb04b).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #21226   +/-   ##
=======================================
  Coverage   92.80%   92.81%           
=======================================
  Files         591      592    +1     
  Lines       64726    64785   +59     
  Branches    18040    18050   +10     
=======================================
+ Hits        60072    60131   +59     
  Misses       4654     4654           
Flag Coverage Δ
css-parsing 28.71% <0.00%> (-0.01%) ⬇️
html5lib 31.19% <39.34%> (+<0.01%) ⬆️
integration 88.97% <98.38%> (+0.03%) ⬆️
test262 45.40% <0.00%> (-0.01%) ⬇️
unit 41.49% <23.21%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@codspeed-hq

codspeed-hq Bot commented Jun 19, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 2 improved benchmarks
❌ 2 regressed benchmarks
✅ 140 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory benchmark "asset-modules-inline", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 389.5 KB 1,230.7 KB -68.35%
Memory benchmark "many-chunks-esm", scenario '{"name":"mode-production","mode":"production"}' 6.7 MB 8.7 MB -22.62%
Memory benchmark "wasm-modules-async", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' 332.4 KB 248.2 KB +33.91%
Memory benchmark "many-modules-commonjs", scenario '{"name":"mode-production","mode":"production"}' 9.7 MB 7.4 MB +32.14%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing bjohansebas:feat/html-iframe-srcdoc (06bb04b) with main (ecc00c0)

Open in CodSpeed

@bjohansebas bjohansebas marked this pull request as ready for review June 19, 2026 16:43
Copilot AI review requested due to automatic review settings June 19, 2026 16:43

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings June 20, 2026 02:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@alexander-akait

Copy link
Copy Markdown
Member

We should not hardcode tags and attributes, it should be live in sources option by default, so other developers can apply this logic to other tags and attributes, also don’t forget, parsing srcdoc is not the same like html file by spec, there is an another logic, our parser is not fully ready for this, we need to introduce other function to parse it as I remember, verify it, also absolute URLs is already handled by output experimental option, don’t ignore them, the same for other types root relative and etc, no need to make todo because nothing to fix

Copilot AI review requested due to automatic review settings June 20, 2026 03:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

* processed HTML read from the nested module's `html` code-generation data,
* re-escaped so the surrounding attribute stays valid.
*/
class HtmlInlineHtmlDependency extends ModuleDependency {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this, it is not treated like a normal HTML document. Also, before that, the entire document is encoded to Base64

@alexander-akait

Copy link
Copy Markdown
Member

@bjohansebas looks good, let's rebase and we can merge

@bjohansebas bjohansebas force-pushed the feat/html-iframe-srcdoc branch from 94d63be to 23fe0b7 Compare June 22, 2026 14:17
@bjohansebas

Copy link
Copy Markdown
Member Author

@alexander-akait done

Comment thread lib/config/defaults.js Outdated
rules.push({
dependency: "html-srcdoc",
generator: {
extract: true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure we really need to extract here, but let's resolve it later, will investigate it in future

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we add support for an "inline" string so I can simplify things?

Comment thread lib/html/HtmlModulesPlugin.js Outdated
break;
}
}
if (inlineSrcdocOnly) continue;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is bad code, it will be bad for performance, any extra loops for dependencies should be used only when no one other solution

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, on it for fix

Copilot AI review requested due to automatic review settings June 22, 2026 16:14
@bjohansebas bjohansebas force-pushed the feat/html-iframe-srcdoc branch from 23fe0b7 to 27b5d47 Compare June 22, 2026 16:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@bjohansebas

bjohansebas commented Jun 22, 2026

Copy link
Copy Markdown
Member Author

Memoize the srcdoc-only check (HtmlModulesPlugin)
Fixture: 200 pages × 80 identical srcdocs shared across many chunks

Metric Before After Improvement
Scan iterations/build 6,400,000 32,000 200× fewer
Time (median) 2553ms 2345ms ~8%
Retained memory 68.9MB 68.9MB no change (zero overhead)

SRCDOC_ASSET_REGEXP pre-filter (HtmlParser)
Fixture: 120 pages × 60 asset-free formatting srcdocs

Metric Before After Improvement
data:text/html modules 60 0 eliminated
Time (median) 1272ms 422ms 3× (~67%)
Peak heap 313MB 166MB ~47%
Retained memory 52.1MB 39.7MB ~24%

Copilot AI review requested due to automatic review settings June 22, 2026 16:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings June 22, 2026 17:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@bjohansebas

Copy link
Copy Markdown
Member Author

#21226 (comment)

With my change to extract "inline", the performance stays the same

@alexander-akait

Copy link
Copy Markdown
Member

@bjohansebas sorry for extra rebase, can you do again and we can merge

- Updated WebpackOptions.json to include `srcdoc` as a valid type for attribute parsing and bundling.
- Modified HtmlParserOptions.check.js to validate `srcdoc` type in the HTML parser options.
- Enhanced snapshot tests to cover new `srcdoc` functionality in iframe elements.
- Created new test cases for handling `srcdoc` in custom tags and attributes.
- Updated type definitions to reflect the addition of `srcdoc` in HtmlParserOptions and SourceType.
- Updated WebpackOptions schema to allow "inline" as a valid option for the extract property, alongside boolean values.
- Modified HtmlGeneratorOptions validation logic to accommodate the new "inline" option.
- Adjusted unit tests to reflect the change in default extraction behavior from true to "inline".
- Updated TypeScript definitions to include "inline" as a valid type for the extract property.
@bjohansebas bjohansebas force-pushed the feat/html-iframe-srcdoc branch from 3475434 to 3447067 Compare June 23, 2026 15:28
Copilot AI review requested due to automatic review settings June 23, 2026 16:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@alexander-akait

Copy link
Copy Markdown
Member

Let’s fix lint, ignore bun, they are a little but unstable, WIP on it

@bjohansebas bjohansebas force-pushed the feat/html-iframe-srcdoc branch from 1c7120f to 0e52f3c Compare June 23, 2026 17:19
Copilot AI review requested due to automatic review settings June 23, 2026 17:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@alexander-akait alexander-akait merged commit 164a6ff into webpack:main Jun 23, 2026
63 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

This PR is packaged and the instant preview is available (164a6ff).

Install it locally:

  • npm
npm i -D webpack@https://pkg.pr.new/webpack@164a6ff
  • yarn
yarn add -D webpack@https://pkg.pr.new/webpack@164a6ff
  • pnpm
pnpm add -D webpack@https://pkg.pr.new/webpack@164a6ff

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.

3 participants