Eager ssr references #7
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is necessary to share any dependency eagerly in SSR. Otherwise every eagerly shared dependency throws a
Shared module is not available for eager consumption. This is not because the share cannot be loaded eagerly, but because references to remotes always return promises (or theinitfunction is a promise).The exception is thrown here: https://github.com/webpack/webpack/blob/main/lib/sharing/ConsumeSharedRuntimeModule.js#L275
rpcProcessreturns a promise this module here is a Promise and will cause the exception above:https://github.com/webpack/webpack/blob/main/lib/sharing/ShareRuntimeModule.js#L100
initreturns a promise thisinitReswill be a promise and will cause the exception abovehttps://github.com/webpack/webpack/blob/main/lib/sharing/ShareRuntimeModule.js#L107
I thought about caching the
remote,getResorinitResfor every succeedinggetcall, but in the end you always want to have the most recent version of the remote script (see caching remark in the bottom).Sharing dependencies does not yet work with nextjs and SSR because next handles all nodejs dependencies as externals. I had to monkey path those for now like this (this also might help with sharing react the "normal" way on SSR?).
I maybe create a feature request for next to allow to disable some externals in their
handleExternalsfunction(Caching-Remark
This change is btw. also necessary if you want to enable cache-invalidation on the server side (which you probably want, to have consistent CSR and SSR renderings), otherwise even clearing the webpack and require cache won't update your SSR-components. Clearing the Webpack cache is currently only possible by writing your own webpack plugin. I did it, but it is not yet ready to share it)