Skip to content
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

feat: add lifecycle hooks for bridge #2875

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft

Conversation

nyqykk
Copy link
Contributor

@nyqykk nyqykk commented Aug 22, 2024

Description

  1. add listener when moduleInfo is ready
  2. support proxy bridge export in onload hook

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 Aug 22, 2024

🦋 Changeset detected

Latest commit: 83e54ad

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

This PR includes changesets to release 38 packages
Name Type
@module-federation/bridge-react Patch
@module-federation/bridge-vue3 Patch
@module-federation/runtime Patch
host Patch
host-v5 Patch
remote1 Patch
remote2 Patch
remote4 Patch
host-vue3 Patch
remote3 Patch
@module-federation/devtools Patch
@module-federation/data-prefetch Patch
@module-federation/dts-plugin Patch
@module-federation/nextjs-mf Patch
@module-federation/node Patch
@module-federation/retry-plugin Patch
@module-federation/runtime-tools Patch
@module-federation/webpack-bundler-runtime Patch
@module-federation/enhanced Patch
@module-federation/modern-js Patch
@module-federation/rspack Patch
3008-runtime-remote Patch
@module-federation/modernjs Patch
modernjs-ssr-dynamic-nested-remote Patch
modernjs-ssr-dynamic-remote-new-version Patch
modernjs-ssr-dynamic-remote Patch
modernjs-ssr-host Patch
modernjs-ssr-nested-remote Patch
modernjs-ssr-remote-new-version Patch
modernjs-ssr-remote Patch
@module-federation/sdk Patch
@module-federation/managers Patch
@module-federation/manifest Patch
@module-federation/third-party-dts-extractor Patch
@module-federation/bridge-shared Patch
@module-federation/bridge-react-webpack-plugin Patch
@module-federation/esbuild Patch
@module-federation/utilities Patch

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

Copy link

netlify bot commented Aug 22, 2024

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit 83e54ad
🔍 Latest deploy log https://app.netlify.com/sites/module-federation-docs/deploys/66f118ad584dd60008bf36b2
😎 Deploy Preview https://deploy-preview-2875--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.

Copy link
Contributor

@squadronai squadronai bot left a comment

Choose a reason for hiding this comment

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

Summary

This pull request introduces a new feature to support proxy bridge export in the onload hook across various parts of the codebase. The key changes include:

  • Adding a listener when the moduleInfo is ready, ensuring the application can properly handle the loading of remote modules.
  • Enabling the proxy bridge export functionality in the onload hook, allowing for seamless integration and customization of the bridge component lifecycle.
  • Introducing new lifecycle hooks, such as beforeBridgeRender and beforeBridgeDestroy, which provide extension points for developers to execute custom logic before the bridge component is rendered or destroyed.
  • Refactoring the logic for handling global and module-level snapshots, ensuring a consistent approach and simplifying the return values.
  • Introducing a new utility function, processModuleAlias, to handle various scenarios related to module naming and normalization.

These changes improve the overall functionality and extensibility of the bridge component, allowing for better integration with the host application and more flexibility in managing the lifecycle of remote components.

File Summaries
File Summary
packages/bridge/bridge-react/src/create.tsx The code changes introduce a new feature to support proxy bridge export in the onload hook. The key modifications include adding a listener when the moduleInfo is ready and enabling the proxy bridge export functionality in the onload hook.
packages/bridge/bridge-react/src/lifecycle.ts This code change introduces a new feature to support proxy bridge export in the onload hook. It adds a listener when the moduleInfo is ready and registers a plugin system with two hooks: beforeBridgeRender and beforeBridgeDestroy. The plugin system is then registered with the host's options, allowing for customization and extension of the bridge lifecycle.
packages/bridge/bridge-react/src/provider.tsx The code changes add support for proxy bridge export in the onload hook, including the addition of a listener when the moduleInfo is ready. The changes also introduce new hooks, beforeBridgeRender and beforeBridgeDestroy, which allow for custom functionality to be executed before the bridge component is rendered or destroyed, respectively.
packages/bridge/bridge-react/src/remote/index.tsx The code changes add support for a proxy bridge export in the onload hook, and introduce a new lifecycle event to be triggered before the remote component is rendered and before it is destroyed. This allows for additional customization and integration points in the bridge module.
packages/bridge/vue3-bridge/src/create.ts The code changes introduce a new feature to support proxy bridge export in the onload hook. The key modifications include adding a listener when the moduleInfo is ready and enabling the proxy bridge export functionality in the onload hook.
packages/bridge/vue3-bridge/src/lifecycle.ts The code changes introduce a new function registerBridgeLifeCycle that sets up a plugin system for managing the lifecycle events of a bridge component. The plugin system includes two hooks: beforeBridgeRender and beforeBridgeDestroy, which can be used to execute custom logic before the bridge component is rendered or destroyed. The function also registers the plugin system with the host application, allowing it to be used throughout the application.
packages/bridge/vue3-bridge/src/provider.ts The code changes introduce a new feature to support proxy bridge export in the onload hook. This includes adding a listener when the moduleInfo is ready and providing lifecycle hooks for rendering and destroying the bridge component.
packages/bridge/vue3-bridge/src/remoteApp.tsx The code changes introduce a new feature to support proxy bridge export in the onload hook. It adds a listener when the moduleInfo is ready and registers a bridge lifecycle hook to emit events before the bridge is rendered and destroyed.
packages/runtime/src/helpers.ts The code changes add a new listener when the moduleInfo is ready and support proxy bridge export in the onload hook. This enhancement allows for improved handling of proxy bridge exports within the application.
packages/runtime/src/module/index.ts The code changes introduce a new feature to support proxy bridge export in the onload hook. The key modifications include adding a listener when moduleInfo is ready and using the processModuleAlias utility function to keep the symbol for the module name in a consistent format.
packages/runtime/src/plugins/snapshot/SnapshotHandler.ts The code changes introduce a new afterLoadSnapshot hook in the SnapshotHandler class. This hook is called after the remote snapshot is loaded, providing an opportunity to perform additional processing or modifications on the loaded snapshot data. The changes also refactor the logic for handling global and module-level snapshots, ensuring a consistent approach and simplifying the return values.
packages/runtime/src/type/config.ts The code changes introduce a new RemoteInfoCommon interface and add a listener when moduleInfo is ready. Additionally, it supports proxy bridge export in the onload hook, which likely enables the application to handle remote module loading and integration more effectively.
packages/runtime/src/type/plugin.ts The code changes introduce a new type LifeCycle that combines several partial types, including CoreLifeCyclePartial, SnapshotLifeCycleCyclePartial, SharedLifeCycleCyclePartial, RemoteLifeCycleCyclePartial, and ModuleLifeCycleCyclePartial. The FederationRuntimePlugin type is then defined as an intersection of the LifeCycle type and an optional generic type T.
packages/runtime/src/utils/plugin.ts The code changes introduce a new feature to support proxy bridge export in the onload hook. The changes include adding a listener when the moduleInfo is ready and extending the registerPlugins function to handle a generic plugin system with a type parameter.
packages/runtime/src/utils/tool.ts The code changes introduce a new utility function called processModuleAlias that takes a module name and a sub-path, and processes them to create a normalized module name. This function is likely used to handle scenarios where the module name may have a trailing slash or the sub-path may start with a dot, ensuring a consistent format for the final module name.

@RussellCanfield
Copy link
Collaborator

@squadronai review

Copy link
Contributor

@squadronai squadronai bot left a comment

Choose a reason for hiding this comment

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

Incremental Review

Comments posted: 6

Configuration

Squadron Mode: essential

Commits Reviewed

b90fa7ded8786022d900081dd7c871f317c5e4b9...f716f180a28d1e7b017db7827045725136fb6d66

Files Reviewed
  • packages/bridge/bridge-react/src/provider.tsx
  • packages/bridge/vue3-bridge/src/provider.ts
  • packages/runtime/src/plugins/snapshot/SnapshotHandler.ts
Files Ignored

These files were ignored due to the filter in the squadron.yaml file.

  • .changeset/great-feet-rule.md

Copy link
Contributor

@squadronai squadronai bot left a comment

Choose a reason for hiding this comment

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

Incremental Review

Comments posted: 6

Configuration

Squadron Mode: essential

Commits Reviewed

865c00bc542e904e24fbcc58c0bb0ec9c8a68c7a...edaffa2490e9c7543640d4c65b6c02602449afed

Files Reviewed
  • packages/bridge/bridge-react/src/provider.tsx
  • packages/bridge/vue3-bridge/src/provider.ts
  • packages/runtime/src/plugins/snapshot/SnapshotHandler.ts
Files Ignored

These files were ignored due to the filter in the squadron.yaml file.

  • .changeset/great-feet-rule.md

Copy link
Contributor

@squadronai squadronai bot left a comment

Choose a reason for hiding this comment

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

Incremental Review

Comments posted: 14

Configuration

Squadron Mode: essential

Commits Reviewed

865c00bc542e904e24fbcc58c0bb0ec9c8a68c7a...fe9ad08d004c3326f7e94ab4862da605264f4465

Files Reviewed
  • packages/bridge/bridge-react/src/create.tsx
  • packages/bridge/bridge-react/src/index.ts
  • packages/bridge/bridge-react/src/lifecycle.ts
  • packages/bridge/bridge-react/src/provider.tsx
  • packages/bridge/bridge-react/src/remote/index.tsx
  • packages/bridge/vue3-bridge/src/create.ts
  • packages/bridge/vue3-bridge/src/index.ts
  • packages/bridge/vue3-bridge/src/lifecycle.ts
  • packages/bridge/vue3-bridge/src/provider.ts
  • packages/bridge/vue3-bridge/src/remoteApp.tsx
  • packages/runtime/src/helpers.ts
  • packages/runtime/src/module/index.ts
  • packages/runtime/src/plugins/snapshot/SnapshotHandler.ts
  • packages/runtime/src/utils/plugin.ts
  • packages/runtime/src/utils/tool.ts
Files Ignored

These files were ignored due to the filter in the squadron.yaml file.

  • .changeset/great-feet-rule.md
  • packages/bridge/bridge-react/package.json
  • packages/bridge/vue3-bridge/package.json
  • pnpm-lock.yaml

Copy link
Contributor

@squadronai squadronai bot left a comment

Choose a reason for hiding this comment

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

Incremental Review

Comments posted: 12

Configuration

Squadron Mode: essential

Commits Reviewed

df760311c10d48b8a08fe7a8236a9b04c1935c90...72577844122be3a0fdfccb4d37cb0443ccf271e8

Files Reviewed
  • packages/bridge/bridge-react/src/create.tsx
  • packages/bridge/bridge-react/src/index.ts
  • packages/bridge/bridge-react/src/lifecycle.ts
  • packages/bridge/bridge-react/src/provider.tsx
  • packages/bridge/bridge-react/src/remote/index.tsx
  • packages/bridge/vue3-bridge/src/create.ts
  • packages/bridge/vue3-bridge/src/index.ts
  • packages/bridge/vue3-bridge/src/lifecycle.ts
  • packages/bridge/vue3-bridge/src/provider.ts
  • packages/bridge/vue3-bridge/src/remoteApp.tsx
  • packages/runtime/src/helpers.ts
  • packages/runtime/src/module/index.ts
  • packages/runtime/src/plugins/snapshot/SnapshotHandler.ts
  • packages/runtime/src/type/config.ts
  • packages/runtime/src/type/plugin.ts
  • packages/runtime/src/utils/plugin.ts
  • packages/runtime/src/utils/tool.ts
Files Ignored

These files were ignored due to the filter in the squadron.yaml file.

  • .changeset/great-feet-rule.md
  • packages/bridge/bridge-react/package.json
  • packages/bridge/vue3-bridge/package.json
  • pnpm-lock.yaml

Copy link
Contributor

@squadronai squadronai bot left a comment

Choose a reason for hiding this comment

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

Incremental Review

Comments posted: 0

Configuration

Squadron Mode: essential

Commits Reviewed

72577844122be3a0fdfccb4d37cb0443ccf271e8...14a30fa47a052733c2efdda5021e530e196380fa

Files Reviewed
  • packages/bridge/vue3-bridge/src/lifecycle.ts
Files Ignored

These files were ignored due to the filter in the squadron.yaml file.

  • .changeset/great-feet-rule.md
  • packages/bridge/bridge-react/package.json
  • packages/bridge/vue3-bridge/package.json
  • pnpm-lock.yaml

Copy link
Contributor

@squadronai squadronai bot left a comment

Choose a reason for hiding this comment

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

Incremental Review

Comments posted: 4

Configuration

Squadron Mode: essential

Commits Reviewed

14a30fa47a052733c2efdda5021e530e196380fa...b47ea80f6142d37e9764123c1eef19606f77e19e

Files Reviewed
  • packages/bridge/bridge-react/src/lifecycle.ts
  • packages/bridge/bridge-react/src/provider.tsx
  • packages/bridge/bridge-react/src/remote/index.tsx
  • packages/bridge/vue3-bridge/src/lifecycle.ts
  • packages/bridge/vue3-bridge/src/remoteApp.tsx
Files Ignored

These files were ignored due to the filter in the squadron.yaml file.

  • .changeset/great-feet-rule.md
  • packages/bridge/bridge-react/package.json
  • packages/bridge/vue3-bridge/package.json
  • pnpm-lock.yaml

@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@module-federation module-federation deleted a comment from squadronai bot Oct 8, 2024
@zhoushaw zhoushaw marked this pull request as draft November 7, 2024 03:47
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.

3 participants