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

Hook problems when calling a React remote from Next #2081

Open
5 tasks done
LukNasc opened this issue Feb 6, 2024 · 6 comments
Open
5 tasks done

Hook problems when calling a React remote from Next #2081

LukNasc opened this issue Feb 6, 2024 · 6 comments
Assignees
Labels
nextjs-mf nextjs-mf package identifier

Comments

@LukNasc
Copy link

LukNasc commented Feb 6, 2024

Describe the bug

I'm trying to call remote modules dynamically using "injectScript", my host app is Next 14 while the remotes can be Angular or React, the Angular remote works correctly, but the React applications cause a Hook error. React apps are usually at version 17.X. Evidence of the error follows.

image

This is my host app using the injectScript

  const bundleLoadConfig: LoadRemoteModule = {
    url:"...",
    global:"...",
    module:"...",
  };

const Component = dynamic<any>(() => loadRemoteModule(bundleLoadConfig), {
    ssr: false,
    loading: loading ?? (() => <p>Loading...</p>),
  });

return <Component>{children}</Component>;

Obs: this is component DynamicBundle and i call this component when i want load dynamic chunk

Reproduction

n/d

Used Package Manager

npm

System Info

System:
    OS: Windows 11 10.0.22621
    CPU: (8) x64 Intel(R) Core(TM) i5-10310U CPU @ 1.70GHz
    Memory: 3.68 GB / 15.73 GB
  Binaries:
    Node: 18.19.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.2.3 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (121.0.2277.98)
    Internet Explorer: 11.0.22621.1

Validations

@zhoushaw zhoushaw added the nextjs-mf nextjs-mf package identifier label Feb 18, 2024
@ScriptedAlchemy
Copy link
Member

ScriptedAlchemy commented Mar 25, 2024

Dont use next/dynamic, use react.lazy
dont use federation/utilities package, use module-federation/runtime
If server side, react needs to be marked as external in the remote server build for commonjs, next cant bundle react correctly

@LukNasc
Copy link
Author

LukNasc commented Apr 1, 2024

Hi, thanks for the help. But I got this error:

image

@ScriptedAlchemy
Copy link
Member

Ignore the type issues and see if it runs.

@LukNasc
Copy link
Author

LukNasc commented Apr 1, 2024

No, i got the same error
302724035-a1d3ab25-552d-4120-8182-eeeebec442c9

@ScriptedAlchemy
Copy link
Member

ScriptedAlchemy commented Apr 1, 2024

Ill need a repo

@ScriptedAlchemy
Copy link
Member

@LukNasc dont use injectScript, use loadRemote from module-federation/runtime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nextjs-mf nextjs-mf package identifier
Projects
None yet
Development

No branches or pull requests

3 participants