garfish icon indicating copy to clipboard operation
garfish copied to clipboard

Proposal: add Lazyload support for Garfish.setExternal

Open moonrailgun opened this issue 1 year ago • 1 comments

Clear and concise description of the problem

If many sub app has same dependency, Like a ui framework, we would like to move it into external with Garfish.setExternal to avoid duplicate bundle.

But if main app not need it, maybe we dont wanna load it first time in main app, but we need to load it before sub app mount.

So maybe Garfish.setExternal can support Lazyload ?

Suggested solution

For example, we can do like its.

in main app:

// avoid ambiguity between Garfish.setExternal
Garfish.setLazyExternal({
  'mobx-react': () => import('mobx-react'),
});

in sub app:

export const provider = reactBridge({
  el: '#root', //mount node
  // a promise that resolves with the react component. Wait for it to resolve before mounting
  loadRootComponent: (appInfo: AppInfo) => {
    _root = getRootDom(appInfo.dom);
    _props = appInfo;
    return Promise.resolve(() => <RootComponent {...appInfo} />);
  },
  errorBoundary: (e: any) => <ErrorBoundary />,
  externalRequired: ["mobx-react"]
});

Alternative

No response

Additional context

If you have no time, i can try to append this feature. Its just a technical discussion

Validations

  • [X] Read the Contributing Guidelines.
  • [X] Check that there isn't already an issue that request the same feature to avoid creating a duplicate.

moonrailgun avatar Jul 06 '22 10:07 moonrailgun

Thanks for your feedback, this problem is great, because we are thinking about how to solve it, but currently we can't directly support the syntax, the current sharing mechanism of external relies on the implementation of commonjs and it is currently a synchronous process, but the problem It will be resolved as soon as possible. We adopt a solution similar to module federation. Thank you again for your feedback. This issue will not be closed until our ability is implemented.

zhoushaw avatar Jul 06 '22 15:07 zhoushaw