Skip to content

feat(runtime): provide a root #3740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

iammerrick
Copy link

@iammerrick iammerrick commented Apr 30, 2025

Description

Allows providing a root element to loadRemote so that it can be used with shadow dom. If one isn't provided it falls back to current document.head behavior.

Related Issue

#3746

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

Would love guidance on how best to test and implement this, if this is even the right API idea.

  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have updated the documentation.

Copy link

changeset-bot bot commented Apr 30, 2025

⚠️ No Changeset found

Latest commit: 7d26e13

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 no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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

netlify bot commented Apr 30, 2025

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit 7d26e13
🔍 Latest deploy log https://app.netlify.com/sites/module-federation-docs/deploys/6812811d5a70d20008e79022
😎 Deploy Preview https://deploy-preview-3740--module-federation-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

</ul>
<Routes>
<Route path="/" element={<Root />} />
<Route path="/remote1" element={<Remote1 />} />
<Route path="/remote2" element={<Remote2 />} />
<Route path="/remote3" element={<Remote3 />} />
Copy link
Author

Choose a reason for hiding this comment

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

Behavior is odd... Loading the page directly attaches the CSS correctly, navigating to it through a link doesn't because css assets is missing in the manifest... It's almost like the built code caches something different than the hardened runtime which uses mf-manifest.json?

@@ -70,6 +70,7 @@ export function preloadAssets(
assets: PreloadAssets,
// It is used to distinguish preload from load remote parallel loading
useLinkPreload = true,
root: HTMLElement = document.head,
Copy link
Author

Choose a reason for hiding this comment

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

A fatal flaw with the current approach is that when you load something (or preload something) it gets cached by id in a global. Subsequent calls to retrieve assets no longer returns those assets. So ultimately, Federation only supports a single root per global. 😞 To fix this I think we'd need to make sure that this code:

https://github.com/iammerrick/module-federation-core/blob/7d26e1325c4520534ee976d131cc6a8e9391c8b5/packages/runtime-core/src/plugins/generate-preload-assets.ts#L248

Somehow respects caches on whether it's been loaded for a specific root. Not assuming a global loading approach.

@2heal1
Copy link
Member

2heal1 commented May 6, 2025

Nice PR ! But I have a small question: Will you only use loadRemote api ? Will you use import with build plugin ?

I ask this is because if you use import to load remote compoent, the root will not be passed . But you can use runtimePlugins to add the root .

@2heal1
Copy link
Member

2heal1 commented May 6, 2025

And can you help add the new feature doc ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants