Skip to content

feat: support universal platform as a web target#5690

Open
bjohansebas wants to merge 8 commits into
nextfrom
universal-target
Open

feat: support universal platform as a web target#5690
bjohansebas wants to merge 8 commits into
nextfrom
universal-target

Conversation

@bjohansebas

Copy link
Copy Markdown
Member

Summary

We already supported this on main—the [node, web] combination—but it was removed when the isWebTarget method was simplified. So I'm adding it back now, along with support for the universal platform. If we were to raise the peer dependency version, we could simplify the function even further, but I don't think it's worth doing that yet.

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 25, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: e62942f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

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

Click here to learn what changesets are, and how to add one.

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

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.

I'm not sure a unit test is worth it, but I'll add one. If you'd rather remove it, that's fine with me. Or if you'd prefer an E2E test, just let me know.

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.

Let's add one e2e test for this and wen can merge

@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.95%. Comparing base (ba139b8) to head (e62942f).

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #5690      +/-   ##
==========================================
+ Coverage   88.93%   88.95%   +0.01%     
==========================================
  Files          13       13              
  Lines        5922     5964      +42     
==========================================
+ Hits         5267     5305      +38     
- Misses        655      659       +4     

☔ 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.

@bjohansebas

Copy link
Copy Markdown
Member Author

We have an issue even with universal, I'm sending a patch to the core because it's still trying to use require in the browser for HMR.

@bjohansebas

Copy link
Copy Markdown
Member Author

Lol, it works locally

@bjohansebas

Copy link
Copy Markdown
Member Author

Lesson learned: always rebase

Comment thread lib/Server.js
Comment on lines +1696 to +1726
// For universal targets `webpack/hot/emitter` uses Node's `events`,
// which breaks in the browser. Swap it for webpack's `EventTarget`
// emitter when available.
if (
compiler.options.output.module &&
compiler.platform.web === null &&
compiler.platform.node === null
) {
let emitter;

try {
emitter = cjsRequire.resolve("webpack/hot/emitter-event-target.js");
} catch {
// older webpack versions do not ship the `EventTarget` emitter
}

if (emitter) {
new webpack.NormalModuleReplacementPlugin(
/emitter(\.js)?$/,
(result) => {
if (
/webpack[/\\]hot|webpack-dev-server[/\\]client/.test(
result.context,
)
) {
result.request = emitter;
}
},
).apply(compiler);
}
}

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.

The same thing needs to be done on the v5 branch, but I'd prefer that we ship v6 first. After that, I can backport the patch to v5 to avoid having to do another rebase on next.

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.

It'll probably be a bit more involved for the v5 branch, but that's something to figure out when I put together that patch.

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.

2 participants