Skip to content

docs: add FederationHost class usage description #3827

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 3 commits into
base: main
Choose a base branch
from

Conversation

2heal1
Copy link
Member

@2heal1 2heal1 commented Jun 9, 2025

Description

add FederationHost class usage description

Related Issue

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

  • 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 Jun 9, 2025

⚠️ No Changeset found

Latest commit: 55c54fd

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 Jun 9, 2025

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit 55c54fd
🔍 Latest deploy log https://app.netlify.com/projects/module-federation-docs/deploys/6846a598ef6a8b00081c08f2
😎 Deploy Preview https://deploy-preview-3827--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 project configuration.

@2heal1
Copy link
Member Author

2heal1 commented Jun 9, 2025

@ScriptedAlchemy I plan to add the FederationHost usage description , what do you think , should we export it ?

@@ -449,6 +449,31 @@ registerPlugins([runtimePlugin()]);

If you want to develop Module Federation plugin, you can read [Module Federation Plugin System](../../plugin/dev/index) for more info.

## FederationHost

In addition to exposing APIs, Federation Runtime also provides the FederationHost class, which you can use to create a FederationHost instance.
Copy link
Member

@ScriptedAlchemy ScriptedAlchemy Jun 10, 2025

Choose a reason for hiding this comment

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

Suggested change
In addition to exposing APIs, Federation Runtime also provides the FederationHost class, which you can use to create a FederationHost instance.
In addition to exposing APIs, the Federation Runtime also provides a FederationHost class, which you can use to create FederationHost instances.


In addition to exposing APIs, Federation Runtime also provides the FederationHost class, which you can use to create a FederationHost instance.

* When to use `FederationHost` ?
Copy link
Member

Choose a reason for hiding this comment

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

it would be a good idea to have small section on "What is FederationHost"

How i explained it to people before was that in the FEDERATION.INSTANCES - each runtime or application who uses module federation creates a FederationHost instance, it represents an both consumer and provider instances of the system. Or something so users understand what federation host actually is for


* When to use `FederationHost` ?

To ensure the uniqueness of the FederationHost instance, after the build plugin creates an instance, it will be stored in memory. The exported APIs all first obtain the FederationHost instance from memory and then call the APIs of the FederationHost instance. This is also why APIs like loadRemote can be used directly.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
To ensure the uniqueness of the FederationHost instance, after the build plugin creates an instance, it will be stored in memory. The exported APIs all first obtain the FederationHost instance from memory and then call the APIs of the FederationHost instance. This is also why APIs like loadRemote can be used directly.
To ensure the uniqueness of the FederationHost instance, after the build plugin creates an instance, it will be stored in memory. The exported APIs all first obtain the FederationHost instance from memory and then call the APIs of the FederationHost instance. This is also why APIs like loadRemote can be used directly from the `module-federation/runtime` package and inherently understand what application container they are attached to.


To ensure the uniqueness of the FederationHost instance, after the build plugin creates an instance, it will be stored in memory. The exported APIs all first obtain the FederationHost instance from memory and then call the APIs of the FederationHost instance. This is also why APIs like loadRemote can be used directly.

However, this singleton pattern also limits the inability to create multiple instances. Therefore, if you need to create a new instance , you can use the FederationHost class to create a new one.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
However, this singleton pattern also limits the inability to create multiple instances. Therefore, if you need to create a new instance , you can use the FederationHost class to create a new one.
However, this singleton pattern also limits the ability to create multiple instances, as it assumes that there is only one instance per bundle. Therefore, if you need to create a new instance , you can use the FederationHost class to create a new one.

@2heal1
Copy link
Member Author

2heal1 commented Jun 10, 2025

got, l will update this

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