Code Monkey home page Code Monkey logo

Comments (23)

ScriptedAlchemy avatar ScriptedAlchemy commented on May 22, 2024

check the shared config, automatic vendor federation plugin Is likely consuming too much code. which example is this?

from module-federation-examples.

xileliu avatar xileliu commented on May 22, 2024

check the shared config, automatic vendor federation plugin Is likely consuming too much code. which example is this?

example:https://github.com/module-federation/module-federation-examples/tree/master/dynamic-system-host
app2 add test code.

from module-federation-examples.

xileliu avatar xileliu commented on May 22, 2024

`dynamic-system-host/app2/src/Widget.js

import React, { useState } from "react";

export default function Widget() {
const [loading, setLoading] = useState(false);
return (
<div
style={{
borderRadius: "4px",
padding: "2em",
backgroundColor: "red",
color: "white",
}}
>
<button onClick={() => setLoading(true)}>click
{loading &&

is loading?

}

App 2 Widget



);
}
`

from module-federation-examples.

zhangwilling avatar zhangwilling commented on May 22, 2024

这个例子本身就有问题。 🤣
=>
这个例子在 hooks 场景下本身就有问题。

from module-federation-examples.

ScriptedAlchemy avatar ScriptedAlchemy commented on May 22, 2024

It looks like where you are requiring from is too dynamic so require(variable) won’t work. Since it’s browser bundle. Webpack will import the entire codebase

That’s what it looks like. Somewhere there’s an import or require that’s too loose

from module-federation-examples.

ScriptedAlchemy avatar ScriptedAlchemy commented on May 22, 2024

i am running it right now with no problem

from module-federation-examples.

ScriptedAlchemy avatar ScriptedAlchemy commented on May 22, 2024

not sure the command you are executing, but it looks like you have livereload in there which most likely will cause all kinds of problems
lerna run --scope @dynamic-system-host/* --parallel start

from module-federation-examples.

ScriptedAlchemy avatar ScriptedAlchemy commented on May 22, 2024

cd dynamic-system-host && yarn start

from module-federation-examples.

zhangwilling avatar zhangwilling commented on May 22, 2024

thanks for your quick response. what problem i face is 'invlid react hooks'. original source code is ok. i means that when use react hooks in widget will cause problem.

from module-federation-examples.

ScriptedAlchemy avatar ScriptedAlchemy commented on May 22, 2024

it is most likely because you run webpack-dev-server.
otehr than that, is react shared in all repos?

from module-federation-examples.

ScriptedAlchemy avatar ScriptedAlchemy commented on May 22, 2024

ohhhh

from module-federation-examples.

ScriptedAlchemy avatar ScriptedAlchemy commented on May 22, 2024

okay i know whats wrong. You're using dynamic code, but shared doesn't work with this syntax. The parser is unable to know whats going to happen and cannot create a remoteModule which performs overrides

from module-federation-examples.

zhangwilling avatar zhangwilling commented on May 22, 2024

React is not shared is the key.

image

after widget loaded, found widget loaded react by itself.

image

from module-federation-examples.

ScriptedAlchemy avatar ScriptedAlchemy commented on May 22, 2024

you have to do somthing like this. Pretty much part of my webpack 4 shim.
Im working on an easier way to access hosts overrides and pass them easily to the remotes but without import() we don't know what is going to happen.
So how it works is when you import(app1/thing)
webpack parser looks for any request that startsWith the name of remote - then once it finds it - we know both the scope and module (app1,thing) and actually perform the overrides during import() because nowhere else does webpack know what you are doing, so we cannot set it up automatically - you are not sharing vendors

if (window?[scope]?.override) {
    window.[scope].override(
        Object.assign(
            {
                react: () => {
                    return Promise.resolve().then(() => {
                        // eslint-disable-next-line
                        return () => require("react");
                    });
                },
                "react-dom": () => {
                    return Promise.resolve().then(() => {
                        // eslint-disable-next-line
                        return () => require("react-dom");
                    });
                },
                "next/link": () => {
                    return Promise.resolve().then(() => {
                        // eslint-disable-next-line
                        return () => require("next/link");
                    });
                }
            },
            __webpack_require__.O
        )
    );
}

from module-federation-examples.

ScriptedAlchemy avatar ScriptedAlchemy commented on May 22, 2024

or whatever you are passing
it can also be import() not require lol, if you wnt

from module-federation-examples.

zhangwilling avatar zhangwilling commented on May 22, 2024

lol, i stared your wp4 shim few days ago, cool thing.

Thanks for your patience.

from module-federation-examples.

zhangwilling avatar zhangwilling commented on May 22, 2024

Actually, i think this problem is react's drawback.

at some cases, we wouldn't share react.

some module (e.g. components) require lower version react (16.13.0), but host app require 16.x.0 (this version may break change) . We must update the react version 😇.

this case is very common in a huge micro frontend app.

from module-federation-examples.

xileliu avatar xileliu commented on May 22, 2024

----- 这个例子本身就有问题。 🤣 ------

=>

这个例子在hooks下本身就有问题

嗯就是用官方的这个例子,发现有这个问题,最终我们需要如何解决这种问题

from module-federation-examples.

zhangwilling avatar zhangwilling commented on May 22, 2024

这个例子本身就有问题。 🤣
=>
这个例子在hooks下本身就有问题

嗯就是用官方的这个例子,发现有这个问题,最终我们需要如何解决这种问题

在统一 react 版本的前提下,你可以不用例子中的这种方式。把这个 widget 改成 本地 private repo,加入 workspace package,再通过 federation shared 这个包。项目中则直接 import 这个包,就不会有 invalid react hook 的问题啦。

from module-federation-examples.

xileliu avatar xileliu commented on May 22, 2024

这个例子本身就有问题。 🤣
=>
这个例子在hooks下本身就有问题

嗯就是用官方的这个例子,发现有这个问题,最终我们需要如何解决这种问题

在统一 react 版本的前提下,你可以不用例子中的这种方式。把这个 widget 改成 本地 private repo,加入 workspace package,再通过 federation shared 这个包。项目中则直接 import 这个包,就不会有 invalid react hook 的问题啦。

app1 app2 app3 app4
如果app2 挂了,按现在的情况在app1 中的其他也都挂了,期望不影响其他的,有好的建议吗

from module-federation-examples.

ScriptedAlchemy avatar ScriptedAlchemy commented on May 22, 2024

Watch this video. It uses dynamic Federation which is what you’re trying to do. It uses the overrides system. https://twitter.com/jherr/status/1263887824203341832?s=21

from module-federation-examples.

ScriptedAlchemy avatar ScriptedAlchemy commented on May 22, 2024

Oh. Well. You pretty much have no choice under that condition. Otherwise you need to not pass components but actually mount new apps that have their own react version.

React is a hard limit. Webpack cannot change the rules of the library :/ cant you update the components or force them to use the host version with newer api? You can use ContainerPlugin and ContainerReferenctPlugin to enforce one direction sharing

from module-federation-examples.

ScriptedAlchemy avatar ScriptedAlchemy commented on May 22, 2024

fixed

from module-federation-examples.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.