Skip to content

Commit

Permalink
Also add script.crossOrigin for hot-reloaded chunks
Browse files Browse the repository at this point in the history
Related: webpack#988

Useful especially for hot-reloaded React 16 apps so that the global
onerror handler can render error boundaries properly.
  • Loading branch information
STRML committed Sep 27, 2017
1 parent 2ee780f commit 6aa3154
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/JsonpMainTemplate.runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
/*globals hotAddUpdateChunk parentHotUpdateCallback document XMLHttpRequest $require$ $hotChunkFilename$ $hotMainFilename$ */
/*globals hotAddUpdateChunk parentHotUpdateCallback document XMLHttpRequest $require$ $hotChunkFilename$ $hotMainFilename$ $crossOriginLoading$ */
module.exports = function() {
function webpackHotUpdateCallback(chunkId, moreModules) { // eslint-disable-line no-unused-vars
hotAddUpdateChunk(chunkId, moreModules);
Expand All @@ -15,6 +15,7 @@ module.exports = function() {
script.type = "text/javascript";
script.charset = "utf-8";
script.src = $require$.p + $hotChunkFilename$;
$crossOriginLoading$;
head.appendChild(script);
}

Expand Down
2 changes: 2 additions & 0 deletions lib/JsonpMainTemplatePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class JsonpMainTemplatePlugin {
mainTemplate.plugin("hot-bootstrap", function(source, chunk, hash) {
const hotUpdateChunkFilename = this.outputOptions.hotUpdateChunkFilename;
const hotUpdateMainFilename = this.outputOptions.hotUpdateMainFilename;
const crossOriginLoading = this.outputOptions.crossOriginLoading;
const hotUpdateFunction = this.outputOptions.hotUpdateFunction;
const currentHotUpdateChunkFilename = this.applyPluginsWaterfall("asset-path", JSON.stringify(hotUpdateChunkFilename), {
hash: `" + ${this.renderCurrentHashCode(hash)} + "`,
Expand All @@ -186,6 +187,7 @@ class JsonpMainTemplatePlugin {
const runtimeSource = Template.getFunctionContent(require("./JsonpMainTemplate.runtime.js"))
.replace(/\/\/\$semicolon/g, ";")
.replace(/\$require\$/g, this.requireFn)
.replace(/\$crossOriginLoading\$/g, crossOriginLoading ? `script.crossOrigin = ${JSON.stringify(crossOriginLoading)}` : "")
.replace(/\$hotMainFilename\$/g, currentHotUpdateMainFilename)
.replace(/\$hotChunkFilename\$/g, currentHotUpdateChunkFilename)
.replace(/\$hash\$/g, JSON.stringify(hash));
Expand Down

0 comments on commit 6aa3154

Please sign in to comment.