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

fix: handle circular init shared #2876

Merged
merged 2 commits into from
Aug 26, 2024
Merged

fix: handle circular init shared #2876

merged 2 commits into from
Aug 26, 2024

Conversation

2heal1
Copy link
Member

@2heal1 2heal1 commented Aug 22, 2024

Description

handle circular init shared

Related Issue

idonava/base-mf-app#2

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: a714fc8

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

This PR includes changesets to release 36 packages
Name Type
@module-federation/webpack-bundler-runtime Patch
@module-federation/runtime Patch
@module-federation/enhanced Patch
@module-federation/runtime-tools Patch
@module-federation/devtools Patch
@module-federation/dts-plugin Patch
@module-federation/nextjs-mf Patch
@module-federation/node Patch
@module-federation/rspack Patch
@module-federation/modern-js Patch
3008-runtime-remote Patch
host Patch
host-v5 Patch
host-vue3 Patch
remote1 Patch
remote2 Patch
remote3 Patch
remote4 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-react Patch
@module-federation/bridge-vue3 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 a714fc8
🔍 Latest deploy log https://app.netlify.com/sites/module-federation-docs/deploys/66c7fbb59dce5d0008336beb
😎 Deploy Preview https://deploy-preview-2876--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 focuses on fixing a bug related to the handling of circular initialization of shared dependencies in the federation runtime. The key changes include:

  • Introduction of a new InitTokens type and a CallFrom type to better manage the initialization process of shared modules.
  • Modifications to the initializeSharing method of the FederationHost class to accept additional options, including an initScope and a from parameter, to handle circular dependencies.
  • Updates to the loadRemote method to accept an optional from parameter of type CallFrom to specify the origin of the remote module loading request.
  • Enhancements to the SharedHandler class to introduce new properties initTokens and initScope to track and manage the initialization process of shared modules, and modifications to the init function of remote modules to pass the initScope parameter.

These changes aim to improve the robustness and reliability of the federation runtime's handling of shared dependencies, especially in scenarios where circular dependencies may arise.

File Summaries
File Summary
packages/runtime/src/core.ts The code changes introduce a new InitTokens type and a CallFrom type, and update the initializeSharing method of the FederationHost class to accept additional options, including an initScope and a from parameter. These changes appear to be part of a fix for handling circular initialization of shared dependencies.
packages/runtime/src/remote/index.ts The code changes introduce a new type called CallFrom to handle the source of the remote module loading, whether it's from the build or runtime. Additionally, the loadRemote method now accepts an optional from parameter of type CallFrom to specify the origin of the remote module loading request.
packages/runtime/src/shared/index.ts The code changes introduce a mechanism to handle circular dependencies in the initialization of shared modules. The key modifications are:
  1. Addition of new properties initTokens and initScope to the SharedHandler class to track and manage the initialization process of shared modules.
  2. Modification of the initializeSharing method to check for circular dependencies and avoid re-initializing shared modules that are already in the process of being initialized.
  3. The init function of remote modules is now called with the initScope parameter to provide information about the current initialization context. |
    | packages/runtime/src/type/config.ts | The code changes introduce a new type InitTokens to represent a record of tokens with their associated data, and modify the InitScope type to be an array of InitTokens. Additionally, a new type CallFrom is introduced to represent the context in which the remote entry is being initialized, either 'build' or 'runtime'. |

@RussellCanfield
Copy link
Contributor

@2heal1 - don't mind me :) just testing out some changes

@RussellCanfield
Copy link
Contributor

@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: 0

Configuration

Squadron Mode: essential

Commits Reviewed

b90fa7ded8786022d900081dd7c871f317c5e4b9...a714fc84999f44a49dbf6e31b127ed6084df825d

Files Reviewed
  • packages/runtime/src/core.ts
  • packages/runtime/src/remote/index.ts
  • packages/runtime/src/shared/index.ts
  • packages/runtime/src/type/config.ts
Files Ignored

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

  • .changeset/itchy-ducks-crash.md
  • packages/webpack-bundler-runtime/src/initializeSharing.ts

@zhoushaw zhoushaw merged commit 24ba96e into main Aug 26, 2024
19 checks passed
@zhoushaw zhoushaw deleted the fix/circular-init-shared branch August 26, 2024 07:40
@2heal1 2heal1 mentioned this pull request Aug 26, 2024
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