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

Including a library, that builds on React, in a remote results into "Cannot read properties of null (reading 'useRef')" #534

Open
pganster opened this issue Oct 24, 2023 · 12 comments

Comments

@pganster
Copy link

pganster commented Oct 24, 2023

Versions

  • vite-plugin-federation: 1.3.2
  • vite: 4.0.5

Reproduction

Essentially I just cloned your react-vite example and added the react-image-gallery library in the remote app. When opening the remote app directly, the gallery is shown as expected. BUT if you open the host app, you will get the error Cannot read properties of null (reading 'useRef').

Steps to reproduce

  1. Clone this reproduction repository.
  2. In root, call pnpm install && pnpm run build && pnpm run serve
  3. Open localhost:5000
  4. See the error

When opening localhost:5001, the error does not occur.

What is Expected?

No error to occur when opening the host app.

What is actually happening?

The error Cannot read properties of null (reading 'useRef') occurring and breaking the host and remote app.

@bluedusk
Copy link

Here's an issue raised before, its not being fixed

#294

@vinodloha
Copy link

Any solution to this issue, I am facing exact above error when remote is loading AG-Grid.

@adirzoari
Copy link

same issue, any solution? @bluedusk @vinodloha @pganster

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


same issue, any solution? @bluedusk @vinodloha @pganster

@colerss
Copy link

colerss commented Mar 6, 2024

Same issue. I have configuration object on my remote which is used to pass on 2 views with their routing data. React is designated as shared in both configs.

View 1 has nested components, useState and useEffect in itself, but no react hooks within the nested components. Renders without issue.
View 2 also has nested components, but these components do use react hooks. It crashes without fault.

For whatever reason, once we go down a level in the component tree of the remote, it just stops being able of finding React, essentially rendering this entire plugin unusable for most complex applications. Given that this issue seems to have been around for over 2 years now with neither a reliable workaround or an update from the developers. I am giving up faith that this will ever be fixed and will explore alternative solutions.

@tecnest-fx4
Copy link

same issue, any solution?

@VladimirTambovtsev
Copy link

Same issue. I have configuration object on my remote which is used to pass on 2 views with their routing data. React is designated as shared in both configs.

View 1 has nested components, useState and useEffect in itself, but no react hooks within the nested components. Renders without issue. View 2 also has nested components, but these components do use react hooks. It crashes without fault.

For whatever reason, once we go down a level in the component tree of the remote, it just stops being able of finding React, essentially rendering this entire plugin unusable for most complex applications. Given that this issue seems to have been around for over 2 years now with neither a reliable workaround or an update from the developers. I am giving up faith that this will ever be fixed and will explore alternative solutions.

@colerss did you find any alternative for vite for microfrontends? I have the same issue.

@FalcoO0n
Copy link

Same issue. I have configuration object on my remote which is used to pass on 2 views with their routing data. React is designated as shared in both configs.

View 1 has nested components, useState and useEffect in itself, but no react hooks within the nested components. Renders without issue. View 2 also has nested components, but these components do use react hooks. It crashes without fault.

For whatever reason, once we go down a level in the component tree of the remote, it just stops being able of finding React, essentially rendering this entire plugin unusable for most complex applications. Given that this issue seems to have been around for over 2 years now with neither a reliable workaround or an update from the developers. I am giving up faith that this will ever be fixed and will explore alternative solutions.

@colerss am facing exactly same issue, the app am building is complex, was using shadcn, it works fine on remote but on host it gives error : Cannot read properties of null (reading 'useRef'). Have you found any solution or alternative?

@boligolov
Copy link

Unfortunately, same issue :(

@dvlptuankiendo
Copy link

me facing same issue, with react-apexcharts in remote app
any update guys?

@TacticCoder
Copy link

Same here

@TacticCoder
Copy link

Ok, an update after some investigating: if you are using a modern bundle of your library, it seems the federation plugin can't handle it.

So, for instance, my solution for react-simple-keyboard is to import the modern index bundle of the component and boom the problem solved, seems that if the federation plugin has a dependency with some legacy JS browser support it can be generate problems

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

No branches or pull requests