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(runtime): use wrapper global instead of using globalThis directly #3179

Merged
merged 1 commit into from
Nov 6, 2024

Conversation

2heal1
Copy link
Member

@2heal1 2heal1 commented Nov 5, 2024

Description

use wrapper global instead of using globalThis directly to ensure legacy browser can use mf runtime as expected

Related Issue

web-infra-dev/rsbuild#3593

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 Nov 5, 2024

🦋 Changeset detected

Latest commit: 492324d

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

This PR includes changesets to release 27 packages
Name Type
@module-federation/runtime 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
@module-federation/rsbuild-plugin Patch
@module-federation/storybook-addon Patch
@module-federation/modernjsapp 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/error-codes Patch
@module-federation/esbuild Patch
@module-federation/utilities Patch
website-new 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 Nov 5, 2024

Deploy Preview for module-federation-docs ready!

Name Link
🔨 Latest commit 492324d
🔍 Latest deploy log https://app.netlify.com/sites/module-federation-docs/deploys/672ae2cbbf6b13000863a9cf
😎 Deploy Preview https://deploy-preview-3179--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 addresses an issue with the module federation runtime, ensuring that it can be used in legacy browsers that do not support the globalThis feature. The changes introduce a new CurrentGlobal variable that is used to access the global object, which is either globalThis or window depending on the environment. This change allows the runtime to work as expected in a wider range of browser environments.

The key changes include:

  • Updating the global.ts file to introduce the CurrentGlobal variable and modifying various functions that interact with the global object to use this variable instead of globalThis directly.
  • Updating the remote/index.ts file to use the CurrentGlobal utility instead of directly accessing globalThis, further improving compatibility and support for legacy browsers.
  • Adding tests to cover the changes and ensure that all new and existing tests pass.
  • Updating the documentation to reflect the changes.

Overall, this pull request enhances the module federation runtime's compatibility and support for a wider range of browser environments, making it more accessible and usable for developers.

File Summaries
File Summary
packages/runtime/src/global.ts The code changes introduce a new CurrentGlobal variable that is used to access the global object, which is either globalThis or window depending on the environment. This change ensures that the runtime can be used in legacy browsers that do not support globalThis. The changes also include updates to various functions that interact with the global object, such as definePropertyGlobalVal, includeOwnProperty, and setGlobalDefaultVal, to use the CurrentGlobal variable instead of globalThis directly.
packages/runtime/src/remote/index.ts The code changes introduce a modification to use the CurrentGlobal utility instead of directly accessing globalThis to ensure legacy browsers can use the module federation runtime as expected. This change aims to provide better compatibility and support for a wider range of browser environments.

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

Configuration

Squadron Mode: essential

Commits Reviewed

849ef9c32fe97ff45b7dceba68903fce5c5326cd...bd86a06c3f318c988449516bc7e94876f9550cb1

Files Reviewed
  • packages/runtime/src/global.ts
  • packages/runtime/src/remote/index.ts
Files Ignored

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

  • .changeset/dry-bats-design.md

@module-federation module-federation deleted a comment from squadronai bot Nov 5, 2024
@module-federation module-federation deleted a comment from squadronai bot Nov 5, 2024
@module-federation module-federation deleted a comment from squadronai bot Nov 5, 2024
@module-federation module-federation deleted a comment from squadronai bot Nov 5, 2024
@module-federation module-federation deleted a comment from squadronai bot Nov 5, 2024
@module-federation module-federation deleted a comment from squadronai bot Nov 5, 2024
@module-federation module-federation deleted a comment from squadronai bot Nov 5, 2024
@module-federation module-federation deleted a comment from squadronai bot Nov 5, 2024
@zhoushaw zhoushaw merged commit 8712967 into main Nov 6, 2024
18 checks passed
@zhoushaw zhoushaw deleted the fix/runtime-global-this branch November 6, 2024 06:35
@2heal1 2heal1 mentioned this pull request Nov 7, 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