Skip to content

Conversation

@ryok90
Copy link
Contributor

@ryok90 ryok90 commented Jan 29, 2026

Fix renderBuiltUrl API signature in pluginAddEntry

Fixes #384

Problem

PR #373 added renderBuiltUrl support but had two critical bugs:

  1. Incomplete API signature: Called renderBuiltUrl(file) with only one parameter, but Vite expects renderBuiltUrl(filename, options)
  2. Missing return type handling: Didn't handle the three possible return types (string, {runtime}, {relative})

This broke compatibility with any renderBuiltUrl implementation that depends on the options parameter, causing "Cannot destructure property of undefined" errors.

Solution

Updated src/plugins/pluginAddEntry.ts (lines 135-191) to:

  1. Call with correct signature: Pass both filename and options object with hostId, hostType, type, and ssr parameters
  2. Handle all return types:
    • string → Use directly
    • {relative: true} → Use filename without base prefix
    • {runtime: "code"} → Warn and fallback (incompatible with HTML <script src="">)
    • undefined → Fallback to default base + file
  3. Per-file resolution: Resolve path for each HTML file with correct hostId

Testing

  • ✅ Build succeeds
  • ✅ All unit tests pass (61 tests)
  • ✅ vite-vite example builds successfully
  • ✅ Tested with reproduction from [Bug]: #384 - build completes without errors
  • ✅ Backward compatible (works without renderBuiltUrl configured)

Preserves PR #373

The fix maintains the original functionality from #373 (issue #372) - renderBuiltUrl transformations are correctly applied to hostInit script tags.

Copy link
Collaborator

@gioboa gioboa left a comment

Choose a reason for hiding this comment

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

Thank you @ryok90 nice fix 💪

@gioboa gioboa merged commit dad36f2 into module-federation:main Jan 30, 2026
4 checks passed
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.

[Bug]:

4 participants