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

无法在remote提供的代码中使用 hooks #248

Open
shinehs opened this issue Sep 21, 2022 · 4 comments
Open

无法在remote提供的代码中使用 hooks #248

shinehs opened this issue Sep 21, 2022 · 4 comments
Labels
enhancement New feature or request
Projects

Comments

@shinehs
Copy link

shinehs commented Sep 21, 2022

Versions

  • vite-plugin-federation: v1.1.9
  • vite: v3.0.3
  • react: 18.2.0

Reproduction

如果在remote提供的模块中,使用例如useEffect这样的hook,在host项目中使用该模块提供的组件的时候,直接会一个V.current.useEffect未定义的错误。

Additional Details

Steps to reproduce

这样提供组件没问题

import React, {useEffect} from "react";

const App = () => {
  return (
    <div
      style={{
        margin: "10px",
        padding: "10px",
        textAlign: "center",
        backgroundColor: "cyan",
      }}
    >
      <h1>组件来自 App 2 中的代码</h1>
    </div>
  );
};

export default App;

这样就会报错

import React, {useEffect} from "react";

const App = () => {
  useEffect(()=>{
    console.log(1);
  },[])
  return (
    <div
      style={{
        margin: "10px",
        padding: "10px",
        textAlign: "center",
        backgroundColor: "cyan",
      }}
    >
      <h1>组件来自 App 2 中的代码</h1>
    </div>
  );
};

export default App;

我的配置:

{
 plugins: [
 react(),
 federation({
        name: 'demo',
        filename: 'entry.js',
        library: { type: 'module' },
        exposes: {
          './Demo': './src/components/index.tsx'
        },
        shared: ['react']
      })
 ]
}

What is Expected?

希望得到回复

What is actually happening?

image
原因是在打包的代码块中:
image

@freedom0116
Copy link

Do vite-plugin-federation support singleton in shared setting?
Just saw that singleton commented up in type define file.
Maybe this is the reason host can't not import remote with react hooks.
and here is the problem I faced now.
image

@flyfishzy
Copy link
Member

Sorry, we don't support singleton in shared yet. I think it can be added to the roadmap.

@flyfishzy flyfishzy added the enhancement New feature or request label Sep 28, 2022
@flyfishzy flyfishzy added this to H2 2022 in Roadmap Sep 28, 2022
@wildfire0304
Copy link

vue2.7 & 3 也很依赖这个 feature, setup script 是需要 defineComponent 的

@caizhisheng
Copy link

caizhisheng commented May 11, 2023

@shinehs 请问问题解决了么?我也遇到同样的问题,在远端服务中不设置shared 本地服务无法加载远端服务的共享模块,在远端服务中设置shared后, 本地服务可以正常加载远端服务的共享模块,这时远端服务自身无法运行,页面空白。(注:远端服务共享的模块为改该服务中的一个页面组件)

???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Roadmap
H2 2022
Development

No branches or pull requests

5 participants