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

wrong React in remote subdependencies (require(react)) #39

Closed
husayt opened this issue Aug 6, 2024 · 13 comments
Closed

wrong React in remote subdependencies (require(react)) #39

husayt opened this issue Aug 6, 2024 · 13 comments

Comments

@husayt
Copy link
Contributor

husayt commented Aug 6, 2024

I am not sure if this is issue with this library, vite or runtime module federation. But It works with webpack module federation.

So basically react in vite remote app works fine, react components render normally. But when I try to use Ag-grid-react I get infamous Invalid hook call. error.

    at Object.useRef (chunk-EFTEWGEA.js:1074:29)
    at AgGridReactUi (ag-grid-react.js:13873:36)
    at renderWithHooks (react-dom.development.js:16305:18)
    at mountIndeterminateComponent (react-dom.development.js:20074:13)
    at beginWork (react-dom.development.js:21587:16)
    at HTMLUnknownElement.callCallback2 (react-dom.development.js:4164:14)
    at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:16)
    at invokeGuardedCallback (react-dom.development.js:4277:31)
    at beginWork$1 (react-dom.development.js:27451:7)
    at performUnitOfWork (react-dom.development.js:26557:12)

Seems the issue with right version react obtained via require inside ag-grid-react (CJS library):

    var react_1 = __importStar(require_react());

@zhangHongEn you just fixed an issue for dynamic imports, maybe we also need fix for require

@husayt husayt changed the title wrong React in remote subdependencies wrong React in remote subdependencies (require(react)) Aug 6, 2024
@zhangHongEn
Copy link
Contributor

@husayt Good issue, I will fix it at noon

@husayt
Copy link
Contributor Author

husayt commented Aug 7, 2024

Also similar error when I use MUI (Material UI)

TypeError: Cannot read properties of null (reading 'useContext')
    at Object.useContext (chunk-EFTEWGEA.js:1062:29)
    at useTheme (chunk-JKYVMHHX.js:3290:32)
    at useTheme2 (chunk-JKYVMHHX.js:3298:10)
    at useThemeProps (chunk-JKYVMHHX.js:3839:15)
    at useThemeProps2 (chunk-JKYVMHHX.js:6377:10)
    at Paper2 (@mui_material.js:1304:17)
    at renderWithHooks (react-dom.development.js:16305:18)
    at updateForwardRef (react-dom.development.js:19226:20)
    at beginWork (react-dom.development.js:21636:16)
    at beginWork$1 (react-dom.development.js:27426:14)

@husayt
Copy link
Contributor Author

husayt commented Aug 7, 2024

@husayt Good issue, I will fix it at noon

I have other issues too, but this is the biggest and most serious issue affecting anyone who would try do any realistic use with 3rd party libraries.

@zhangHongEn
Copy link
Contributor

@husayt Good issue, I will fix it at noon

I have other issues too, but this is the biggest and most serious issue affecting anyone who would try do any realistic use with 3rd party libraries.

Yes, this is a very important bug, but I didn't have time to look at it until 7 hours later.

@husayt
Copy link
Contributor Author

husayt commented Aug 7, 2024

Yes, this is a very important bug, but I didn't have time to look at it until 7 hours later.

that is fine, i posted some other issues as well. I just wanted to say that this one is the most pressing one among them.

@gioboa
Copy link
Collaborator

gioboa commented Aug 7, 2024

@zhangHongEn you are doing great, take your time to avoid burnouts 🚀

@zhangHongEn
Copy link
Contributor

Vite pre-built subdependencies cannot be proxied in the usual way. I have found a solution, but I have been too busy recently and may need to wait for two days.

@zhangHongEn
Copy link
Contributor

zhangHongEn@06dc35d
All that remains is to make this step automatic.

@husayt
Copy link
Contributor Author

husayt commented Aug 8, 2024

I made a simple repro to test this case. Will try to commit that later. But gist of it I added another remote with
with these dependencies

  "dependencies": {
    "@module-federation/vite": "workspace:*",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "vue": "^3.4.29",
    "vue-router": "^4.4.0",
    "ag-grid-community": "^30.2.0",
    "ag-grid-react": "^30.2.0"
  },

and AgGridDemo.jsx

import 'ag-grid-community/styles/ag-grid.css';
import 'ag-grid-community/styles/ag-theme-alpine.css';
import { AgGridReact } from 'ag-grid-react';
import { useState } from 'react';


export const AgGridDemo = ({  }) => {
  const [rowData] = useState([
    { make: 'Toyota', model: 'Celica', price: 35000 },
    { make: 'Ford', model: 'Mondeo', price: 32000 },
    { make: 'Porsche', model: 'Boxter', price: 72000 },
  ]);

  const [columnDefs] = useState([{ field: 'make' }, { field: 'model' }, { field: 'price' }]);

  return (
    <div className="App">
      <div style={{ display: 'flex', flexDirection: 'row' }}>
        <div
          id="grid1"
          className="ag-theme-alpine"
          style={{ height: 400, width: 600, margin: '20px' }}
        >
          <AgGridReact rowData={rowData} columnDefs={columnDefs}></AgGridReact>
        </div>
        <div
          id="grid2"
          className="ag-theme-alpine"
          style={{ height: 400, width: 600, margin: '20px' }}
        >
          <AgGridReact rowData={rowData} columnDefs={columnDefs}></AgGridReact>
        </div>
      </div>
    </div>
  );
};

When running this remote on its own all works fine.

But when I try to run it from another host via MF I get the same error

Object.useRef (chunk-D5PPDA7K.js:1074:29)
    at AgGridReactUi (ag-grid-react.js:69725:36)
    at renderWithHooks (chunk-BISVECJP.js:11548:26)
    at mountIndeterminateComponent (chunk-BISVECJP.js:14926:21)
    at beginWork (chunk-BISVECJP.js:15914:22)
    at HTMLUnknownElement.callCallback2 (chunk-BISVECJP.js:3674:22)
    at Object.invokeGuardedCallbackDev (chunk-BISVECJP.js:3699:24)
    at invokeGuardedCallback (chunk-BISVECJP.js:3733:39)
    at beginWork$1 (chunk-BISVECJP.js:19765:15)
    at performUnitOfWork (chunk-BISVECJP.js:19198:20)

@husayt
Copy link
Contributor Author

husayt commented Aug 8, 2024

zhangHongEn@06dc35d All that remains is to make this step automatic.

This looks very promising. Tried to test the proposed solution on the example above. Seems I am missing something, so I have to wait for proper solution. Very excited to finally get this working. Thank you

@zhangHongEn
Copy link
Contributor

zhangHongEn commented Aug 9, 2024

@husayt Finally finished, the sub-dependency is running well now, thank you for finding this problem, I will test it again and issue a PR tomorrow night

zhangHongEn@d79fe18

@zhangHongEn
Copy link
Contributor

compeleted

gioboa pushed a commit that referenced this issue Aug 10, 2024
* fix: pre-bunding

* feat: add pre-bunding subdependencies demo

* fix: exposes .

* fix: remotes support namespace
@gioboa gioboa closed this as completed Aug 10, 2024
@husayt
Copy link
Contributor Author

husayt commented Aug 10, 2024

Thank you @zhangHongEn, but now it is completely broken for me. I tried to run latest examples and I get "Please call init first" error on both host and remote examples.

image

Seems it is the same issue as this: #42 (comment)

When i try "remoteEntry.js" I get this

//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImVtcHR5LmpzP19fbWZfX3dyYXBSZW1vdGVFbnRyeV9fIl0sInNvdXJjZXNDb250ZW50IjpbIiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=

gioboa added a commit that referenced this issue Sep 15, 2024
* feat: new plugin configuration (#28)

* init ts (#29)

* fix: tsconfig

* fix: issues 2 3

* feat: rust demo build and preview

---------

Co-authored-by: 张洪恩 <zhanghongen@bwcj.com>

* feat: support runtime plugins (#30)

Co-authored-by: Sergey Melukov <s.melukov@vk.team>

* fix: Ensure @module-federation/runtime singleton (#31)

* fix: Ensure @module-federation/runtime singleton

* fix: build preview

---------

Co-authored-by: 张洪恩 <zhanghongen@bwcj.com>

* feat: add packageManager

* fix: remoteEntry support hash; format dynamic es module (#35)

* 1.0.0-alpha-7c3ba59

* fix: remove default export (#37)

* fix: remove pkg-pr-new

* chore: add PR title check

* 1.0.0-alpha-ffc6e23

* fix: #36 and dynamic import (#38)

* fix: dynamic import

* fix: #36

* 1.0.0-alpha-54ad191

* 1.0.0-alpha-80b7215

* fix: #39 #44 #45 (#46)

* fix: pre-bunding

* feat: add pre-bunding subdependencies demo

* fix: exposes .

* fix: remotes support namespace

* 1.0.0-alpha-4a73cd4

* fix: windows remoteEntry error (#48)

Co-authored-by: 张洪恩 <zhanghongen@bwcj.com>

* feat: updated examples (#50)

* 1.0.0-alpha-def937d

* fix updated examples (#51)

* fix: #47 (#53)

* 1.0.0-alpha-10e1f83

* improved  examples with MUI and etc (#55)

* fix: #56 #41 (#58)

* 1.0.0-alpha-6cae9ab

* mfruntime update and new examples (#62)

* fix: #61 (#63)

Co-authored-by: 张洪恩 <zhanghongen@bwcj.com>

* 1.0.0-alpha-51eeeb6

* feat: shared-slash (#67)

* feat: shared slash

* feat: shared slash

* feat: preview examples

* feat: remove an-empty-js-file

* fix: remove console

* optimization: reduce dev mode page reload

* Optimize code and comments

* fix: 64

* fix: only slash

---------

Co-authored-by: 张洪恩 <zhanghongen@bwcj.com>

* 1.0.0-alpha-f87d7d3

* fix: nx #40 (#69)

* 1.0.0-alpha-661e052

* fix: #68 (#71)

* fix: #68

* fix: #68

* fix: windows Multi-Pack

* Optimization: Reduce file writing

* Optimization: code format

* fix: support nx monorepo

---------

Co-authored-by: 张洪恩 <zhanghongen@bwcj.com>

* 1.0.0-alpha-1aa30c0

* fix: monorepo (#72)

Co-authored-by: 张洪恩 <zhanghongen@bwcj.com>

* feat: add Nuxt example (#75)

* Add Nuxt host example

* Gitignore generated .__mf__win folder

---------

Co-authored-by: David Sellén <david.sellen@bolagsverket.se>
Co-authored-by: David Sellén <david.sellen@gmail.com>

* chore: update module federation and more examples (#81)

* fix: #78 (#79)

* fix: #78

* Update src/utils/normalizeOptimizeDeps.ts

Co-authored-by: Sergey Melyukov <s.melukov@gmail.com>

---------

Co-authored-by: 张洪恩 <zhanghongen@bwcj.com>
Co-authored-by: Sergey Melyukov <s.melukov@gmail.com>

* fix: #77 (#82)

* 1.0.0-alpha-2f53b4e

* docs: update Vue example link

* docs: update React example link

* docs: update README

* fix: Remote virtual module path (#84)

Co-authored-by: 张洪恩 <zhanghongen@bwcj.com>

* 1.0.0-alpha-c13dc95

* feat: add improvements (#86)

* fix: Remote virtual module path

* examples: nuxt(Unfinished)

* feat: mf-manifest; Register remote on demand

* doc: roadmap

* doc: npm url

* Delete src/utils/getLocalSharedImportMap_windows.ts

---------

Co-authored-by: 张洪恩 <zhanghongen@bwcj.com>

---------

Co-authored-by: zhn <zhang_h_n@163.com>
Co-authored-by: 张洪恩 <zhanghongen@bwcj.com>
Co-authored-by: Sergey Melyukov <s.melukov@gmail.com>
Co-authored-by: Sergey Melukov <s.melukov@vk.team>
Co-authored-by: HG <husayt@gmail.com>
Co-authored-by: David sellén <sellen.david@gmail.com>
Co-authored-by: David Sellén <david.sellen@bolagsverket.se>
Co-authored-by: David Sellén <david.sellen@gmail.com>
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

3 participants