Giter Club home page Giter Club logo

Comments (8)

ScriptedAlchemy avatar ScriptedAlchemy commented on August 30, 2024

federation is assign based, it object assigns new over old, since the keys (version) is the same - it doesn't matter to init order.
You can put it into loaded-first which may prevent this.

import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';

const sharedStrategy: () => FederationRuntimePlugin = () => ({
  name: 'shared-strategy-plugin',
  beforeInit(args) {
    const { userOptions } = args;
    const shared = userOptions.shared;
    if (shared) {
      Object.keys(shared).forEach((sharedKey) => {
        const sharedConfigs = shared[sharedKey];
        const arraySharedConfigs = Array.isArray(sharedConfigs)
          ? sharedConfigs
          : [sharedConfigs];
        arraySharedConfigs.forEach((s) => {
          s.strategy = 'loaded-first';
        });
      });
    }
    return args;
  },
});
export default sharedStrategy;

from universe.

MadaraUchiha-314 avatar MadaraUchiha-314 commented on August 30, 2024

The solution works! but .....

It works when I use @module-federation/enhanced/webpack. But when I use webpack/lib/container/ModuleFederationPlugin.js, it doesn't work because there's no concept of runtime plugins in that.

I have updated my above mentioned stackblitz example to reflect it.

But interestingly, beforeInit is not even called for the MF 1.0 remote. Even if it is called, because there's no federation runtime, the only way a MF 1.0 remote will not wipe out the share scope is if we forcefully add loaded: true to the packages provided by the host.

Hence my proposal is to modify the SharedBaseArgs to add one additional param to mark any module as loaded. If loaded: true is an internal state, we can rename it to something else like preferred or whatever, but internally it will mark that module as loaded: true after which MF 1.0 container will start using it.

from universe.

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.