Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: broken library output by webpackPrefetch #13431

Merged

Conversation

Shinyaigeek
Copy link
Contributor

Fix: #12993

dynamic import with webpackPrefetch: true will cause a broken library output in development mode.
This PR will fix this issue

What kind of change does this PR introduce?

bugfix

Did you add tests for your changes?

yes

Does this PR introduce a breaking change?

no

What needs to be documented once your changes are merged?

none

@webpack-bot
Copy link
Contributor

For maintainers only:

  • This needs to be documented (issue in webpack/webpack.js.org will be filed when merged)
  • This needs to be backported to webpack 4 (issue will be created when merged)

Comment on lines 1092 to 1098
buf2.push(
`__webpack_exports__ = ${RuntimeGlobals.onChunksLoaded}(__webpack_exports__);`
);
if (runtimeRequirements.has(RuntimeGlobals.prefetchChunk)) {
buf2.push(`${RuntimeGlobals.onChunksLoaded}();`);
} else {
buf2.push(
`__webpack_exports__ = ${RuntimeGlobals.onChunksLoaded}(__webpack_exports__);`
);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought onChunksLoaded fired by webpackPrefetch should not overwrite __webpack_exports__ because prefetchChunkHandlers return void, so I fixed issue 12993 by changing how to call onChunksLoaded with prefetchChunk.

If my approach is not correct or a test case is not enough, please feel free to close this PR or request changes.

@webpack-bot
Copy link
Contributor

Thank you for your pull request! The most important CI builds succeeded, we’ll review the pull request soon.

@agawley
Copy link

agawley commented Jul 15, 2021

Any chance this (or an alternative fix) will make it to prod soon? Happy to help move along if I can.

@sokra sokra force-pushed the fix/overwritten_webpack__exports_onChunksLoaded branch from bc456ff to 8ce0f24 Compare July 16, 2021 09:18
@sokra sokra force-pushed the fix/overwritten_webpack__exports_onChunksLoaded branch from 8ce0f24 to c469adc Compare July 16, 2021 16:11
@sokra sokra merged commit e15752c into webpack:main Jul 16, 2021
@sokra
Copy link
Member

sokra commented Jul 16, 2021

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

webpackPrefetch: true breaks library output
4 participants