web-infra-dev / rspack

The fast Rust-based web bundler with webpack-compatible API 🦀️
https://rspack.dev
MIT License
10.16k stars 577 forks source link

[Bug]: Shared context doesn't seem to work with runtime module federation[Bug]: #7066

Open AdamJSoftware opened 4 months ago

AdamJSoftware commented 4 months ago

System Info

Need to install the following packages: envinfo@7.13.0 Ok to proceed? (y) y

System: OS: Linux 6.1 Manjaro Linux CPU: (12) x64 Intel(R) Core(TM) i7-9850H CPU @ 2.60GHz Memory: 13.32 GB / 30.96 GB Container: Yes Shell: 3.7.1 - /usr/bin/fish Binaries: Node: 18.19.0 - /run/user/1000/fnm_multishells/305667_1720381529332/bin/node Yarn: 1.22.22 - /run/user/1000/fnm_multishells/305667_1720381529332/bin/yarn npm: 10.2.3 - /run/user/1000/fnm_multishells/305667_1720381529332/bin/npm npmPackages: @rspack/cli: ^1.0.0-alpha.0 => 1.0.0-alpha.0

Details

I am trying to share mantine with module federation. However, mantine requires a context to be created. Even though I have specified @mantine/core as a singleton in both the remote and shell. It still says that the context has not been initialized and the app crashes.

Reproduce link

https://github.com/AdamJSoftware/rspack-module-federation-bug

Reproduce Steps

  1. cd remote
  2. yarn install
  3. yarn dev
  4. cd shell
  5. yarn install
  6. yarn dev
  7. Navigate to http://localhost:3000 and you will see
    react.development.js:1618 Uncaught TypeError: Cannot read properties of null (reading 'useContext')
    at useContext (react.development.js:1618:1)
    at useMantineTheme (MantineThemeProvider.mjs:10:1)
    at useProps (use-props.mjs:9:1)
    at Text.mjs:46:1
    at renderWithHooks (react-dom.development.js:15486:1)
    at updateForwardRef (react-dom.development.js:19245:1)
    at beginWork (react-dom.development.js:21675:1)
    at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:1)
    at invokeGuardedCallback (react-dom.development.js:4277:1)
AdamJSoftware commented 4 months ago

Similar issue is happening here: https://github.com/vercel/next.js/discussions/64887

Could this be an issue with the module federation spec itself?

stale[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity. If this issue is still affecting you, please leave any comment (for example, "bump"). We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!