core icon indicating copy to clipboard operation
core copied to clipboard

Add support for eager "exposed" modules

Open MadaraUchiha-314 opened this issue 1 year ago • 8 comments

Clear and concise description of the problem

There's no way to mark exposed modules as eager and having the ability to load them synchronously.

Suggested solution

Shared modules can be marked as eager in the shared config thus adding the ability to load them synchronously.

Internally eager shared modules are added to the remote entry.

The same can be done for exposed modules.

The only caveat is that if the exposed module imports a shared module, then that module also has to be marked as eager, otherwise one will get the error:

Uncaught Error: Shared module is not available for eager consumption

Alternative

The only workaround I have found is to also "share" the exposed module and then mark the shared module as eager. But this has the unwanted side effect of having that module in the shared scope. Additionally exposed modules don't have versions, so having them in the shared scope doesn't make sense.

Additional context

No response

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.

MadaraUchiha-314 avatar May 30 '24 04:05 MadaraUchiha-314

Hmm I don't know understand the requirement . Do you mean expose can be config as the same as shared like 'eager:true', and then it will be loaded with remoteEntry ?

Can you add more details about why you need this change ? Or add pseudocode

2heal1 avatar Jun 03 '24 02:06 2heal1

@2heal1 some exposed modules may be small or may be critical and he wants to avoid additional network call.

Basically like how shared eager=true works, but for exposes.

So eager exposed doesn't make extra chunk, it's just in the remote entry.

ScriptedAlchemy avatar Jun 03 '24 12:06 ScriptedAlchemy

The problem with eager module loading will be that you lose the async boundary - if eager expose needs react for example - it will fail since react is not ready / may not be ready at time its requested. There would need to be at least one async chunk call.

ScriptedAlchemy avatar Jun 11 '24 23:06 ScriptedAlchemy

There would need to be at least one async chunk call.

Not necessarily.

  • If a dependency that the eager module requires is "shared" then it also has to be eager.
  • Else the bundler will just bundle it in the remoteEntry since it will be a regular import.
  • If a dependency is imported using dynamic imports, then we can
    • inline that dynamic import
    • let it be a dynamic import and let the exposed module handle it. The exposed module still be available synchronously.

MadaraUchiha-314 avatar Jun 12 '24 07:06 MadaraUchiha-314

The same issue will exist when an eager shared dependency has a peer on another shared dependency which might or might not be marked as eager. For e.g. react and react-dom (declares react as a peer)

MadaraUchiha-314 avatar Jun 12 '24 16:06 MadaraUchiha-314

Stale issue message

github-actions[bot] avatar Aug 12 '24 15:08 github-actions[bot]

@ScriptedAlchemy @2heal1 If this is an acceptable proposal, I can send in a PR implementing it.

MadaraUchiha-314 avatar Aug 13 '24 00:08 MadaraUchiha-314

If you have an idea of how to add it. Then let's take a look.

ScriptedAlchemy avatar Aug 13 '24 19:08 ScriptedAlchemy

Stale issue message

github-actions[bot] avatar Oct 13 '24 15:10 github-actions[bot]