Skip to content
This repository was archived by the owner on May 31, 2021. It is now read-only.

Commit 9b821fd

Browse files
fix: hmr issue where base64 links would cause loader to fail (faceyspacey#177)
fix: hmr asset order fixed, updates cascade correctly
1 parent 0a08f8f commit 9b821fd

File tree

3 files changed

+159
-10
lines changed

3 files changed

+159
-10
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
"loader-utils": "^1.1.0",
7070
"normalize-url": "1.9.1",
7171
"schema-utils": "^1.0.0",
72+
"webpack-external-import": "^0.0.1-beta.15",
7273
"webpack-sources": "^1.1.0"
7374
},
7475
"devDependencies": {

src/hmr/hotModuleReplacement.js

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ function getCurrentScriptUrl(moduleId) {
7979

8080
function updateCss(el, url) {
8181
if (!url) {
82+
if (!el.href) {
83+
return;
84+
}
85+
8286
// eslint-disable-next-line
8387
url = el.href.split('?')[0];
8488
}
@@ -116,7 +120,11 @@ function updateCss(el, url) {
116120

117121
newEl.href = `${url}?${Date.now()}`;
118122

119-
el.parentNode.insertBefore(newEl, el);
123+
if (el.nextSibling) {
124+
el.parentNode.insertBefore(newEl, el.nextSibling);
125+
} else {
126+
el.parentNode.appendChild(newEl);
127+
}
120128
}
121129

122130
function getReloadUrl(href, src) {
@@ -140,6 +148,10 @@ function reloadStyle(src) {
140148
let loaded = false;
141149

142150
forEach.call(elements, (el) => {
151+
if (!el.href) {
152+
return;
153+
}
154+
143155
const url = getReloadUrl(el.href, src);
144156

145157
if (!isUrlRequest(url)) {
@@ -152,6 +164,7 @@ function reloadStyle(src) {
152164

153165
if (url) {
154166
updateCss(el, url);
167+
155168
loaded = true;
156169
}
157170
});
@@ -174,13 +187,8 @@ function reloadAll() {
174187
function isUrlRequest(url) {
175188
// An URL is not an request if
176189

177-
// 1. It's a protocol-relative
178-
if (/^\/\//.test(url)) {
179-
return false;
180-
}
181-
182-
// 2. Its a `#` link
183-
if (/^#/.test(url)) {
190+
// It is not http or https
191+
if (!/^https?:/i.test(url)) {
184192
return false;
185193
}
186194

yarn.lock

Lines changed: 142 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,6 +1565,13 @@ babel-jest@^24.8.0:
15651565
chalk "^2.4.2"
15661566
slash "^2.0.0"
15671567

1568+
babel-messages@^6.23.0:
1569+
version "6.23.0"
1570+
resolved "https://registry.yarnpkg.com/babel-messages/-/babel-messages-6.23.0.tgz#f3cdf4703858035b2a2951c6ec5edf6c62f2630e"
1571+
integrity sha1-8830cDhYA1sqKVHG7F7fbGLyYw4=
1572+
dependencies:
1573+
babel-runtime "^6.22.0"
1574+
15681575
babel-plugin-istanbul@^5.1.0:
15691576
version "5.1.4"
15701577
resolved "https://registry.yarnpkg.com/babel-plugin-istanbul/-/babel-plugin-istanbul-5.1.4.tgz#841d16b9a58eeb407a0ddce622ba02fe87a752ba"
@@ -1598,13 +1605,43 @@ babel-preset-jest@^24.6.0:
15981605
"@babel/plugin-syntax-object-rest-spread" "^7.0.0"
15991606
babel-plugin-jest-hoist "^24.6.0"
16001607

1601-
babel-runtime@6.26.0, babel-runtime@^6.23.0, babel-runtime@^6.26.0:
1608+
babel-runtime@6.26.0, babel-runtime@^6.22.0, babel-runtime@^6.23.0, babel-runtime@^6.26.0:
16021609
version "6.26.0"
16031610
resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe"
16041611
dependencies:
16051612
core-js "^2.4.0"
16061613
regenerator-runtime "^0.11.0"
16071614

1615+
babel-traverse@^6.26.0:
1616+
version "6.26.0"
1617+
resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.26.0.tgz#46a9cbd7edcc62c8e5c064e2d2d8d0f4035766ee"
1618+
integrity sha1-RqnL1+3MYsjlwGTi0tjQ9ANXZu4=
1619+
dependencies:
1620+
babel-code-frame "^6.26.0"
1621+
babel-messages "^6.23.0"
1622+
babel-runtime "^6.26.0"
1623+
babel-types "^6.26.0"
1624+
babylon "^6.18.0"
1625+
debug "^2.6.8"
1626+
globals "^9.18.0"
1627+
invariant "^2.2.2"
1628+
lodash "^4.17.4"
1629+
1630+
babel-types@^6.26.0:
1631+
version "6.26.0"
1632+
resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.26.0.tgz#a3b073f94ab49eb6fa55cd65227a334380632497"
1633+
integrity sha1-o7Bz+Uq0nrb6Vc1lInozQ4BjJJc=
1634+
dependencies:
1635+
babel-runtime "^6.26.0"
1636+
esutils "^2.0.2"
1637+
lodash "^4.17.4"
1638+
to-fast-properties "^1.0.3"
1639+
1640+
babylon@^6.18.0:
1641+
version "6.18.0"
1642+
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3"
1643+
integrity sha512-q/UEjfGJ2Cm3oKV71DJz9d25TPnq5rhBVL2Q4fA5wcC3jcrdn7+SssEybFIxwAvvP+YCsCYNKughoF33GxgycQ==
1644+
16081645
balanced-match@^1.0.0:
16091646
version "1.0.0"
16101647
resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767"
@@ -1659,6 +1696,11 @@ bluebird@^3.4.7, bluebird@^3.5.3:
16591696
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.3.tgz#7d01c6f9616c9a51ab0f8c549a79dfe6ec33efa7"
16601697
integrity sha512-/qKPUQlaW1OyR51WeCPBvRnAlnZFUJkCSG5HzGnuIqhgyJtF+T94lFnn33eiazjRm2LAHVy2guNnaq48X9SJuw==
16611698

1699+
bluebird@^3.5.5:
1700+
version "3.5.5"
1701+
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.5.tgz#a8d0afd73251effbbd5fe384a77d73003c17a71f"
1702+
integrity sha512-5am6HnnfN+urzt4yfg7IgTbotDjIT/u8AJpEt0sIU9FtXfVeezXAPKswrG+xKUCOYAINpSdgZVDU6QFh+cuH3w==
1703+
16621704
bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.4.0:
16631705
version "4.11.8"
16641706
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f"
@@ -1877,6 +1919,26 @@ cacache@^11.0.2:
18771919
unique-filename "^1.1.1"
18781920
y18n "^4.0.0"
18791921

1922+
cacache@^11.3.2:
1923+
version "11.3.3"
1924+
resolved "https://registry.yarnpkg.com/cacache/-/cacache-11.3.3.tgz#8bd29df8c6a718a6ebd2d010da4d7972ae3bbadc"
1925+
integrity sha512-p8WcneCytvzPxhDvYp31PD039vi77I12W+/KfR9S8AZbaiARFBCpsPJS+9uhWfeBfeAtW7o/4vt3MUqLkbY6nA==
1926+
dependencies:
1927+
bluebird "^3.5.5"
1928+
chownr "^1.1.1"
1929+
figgy-pudding "^3.5.1"
1930+
glob "^7.1.4"
1931+
graceful-fs "^4.1.15"
1932+
lru-cache "^5.1.1"
1933+
mississippi "^3.0.0"
1934+
mkdirp "^0.5.1"
1935+
move-concurrently "^1.0.1"
1936+
promise-inflight "^1.0.1"
1937+
rimraf "^2.6.3"
1938+
ssri "^6.0.1"
1939+
unique-filename "^1.1.1"
1940+
y18n "^4.0.0"
1941+
18801942
cache-base@^1.0.1:
18811943
version "1.0.1"
18821944
resolved "https://registry.yarnpkg.com/cache-base/-/cache-base-1.0.1.tgz#0a7f46416831c8b662ee36fe4e7c59d76f666ab2"
@@ -3669,6 +3731,15 @@ find-cache-dir@^2.0.0:
36693731
make-dir "^2.0.0"
36703732
pkg-dir "^3.0.0"
36713733

3734+
find-cache-dir@^3.0.0:
3735+
version "3.0.0"
3736+
resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-3.0.0.tgz#cd4b7dd97b7185b7e17dbfe2d6e4115ee3eeb8fc"
3737+
integrity sha512-t7ulV1fmbxh5G9l/492O1p5+EBbr3uwpt6odhFTMc+nWyhmbloe+ja9BZ8pIBtqFWhOmCWVjx+pTW4zDkFoclw==
3738+
dependencies:
3739+
commondir "^1.0.1"
3740+
make-dir "^3.0.0"
3741+
pkg-dir "^4.1.0"
3742+
36723743
find-parent-dir@^0.3.0:
36733744
version "0.3.0"
36743745
resolved "https://registry.yarnpkg.com/find-parent-dir/-/find-parent-dir-0.3.0.tgz#33c44b429ab2b2f0646299c5f9f718f376ff8d54"
@@ -3801,6 +3872,15 @@ fs-extra@^7.0.0:
38013872
jsonfile "^4.0.0"
38023873
universalify "^0.1.0"
38033874

3875+
fs-extra@^8.0.1:
3876+
version "8.1.0"
3877+
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0"
3878+
integrity sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==
3879+
dependencies:
3880+
graceful-fs "^4.2.0"
3881+
jsonfile "^4.0.0"
3882+
universalify "^0.1.0"
3883+
38043884
fs-minipass@^1.2.5:
38053885
version "1.2.5"
38063886
resolved "https://registry.yarnpkg.com/fs-minipass/-/fs-minipass-1.2.5.tgz#06c277218454ec288df77ada54a03b8702aacb9d"
@@ -4027,6 +4107,18 @@ glob@^7.0.5, glob@^7.1.3:
40274107
once "^1.3.0"
40284108
path-is-absolute "^1.0.0"
40294109

4110+
glob@^7.1.4:
4111+
version "7.1.4"
4112+
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.4.tgz#aa608a2f6c577ad357e1ae5a5c26d9a8d1969255"
4113+
integrity sha512-hkLPepehmnKk41pUGm3sYxoFs/umurYfYJCerbXEyFIWcAzvpipAgVkBqqT9RBKMGjnq6kMuyYwha6csxbiM1A==
4114+
dependencies:
4115+
fs.realpath "^1.0.0"
4116+
inflight "^1.0.4"
4117+
inherits "2"
4118+
minimatch "^3.0.4"
4119+
once "^1.3.0"
4120+
path-is-absolute "^1.0.0"
4121+
40304122
global-dirs@^0.1.0, global-dirs@^0.1.1:
40314123
version "0.1.1"
40324124
resolved "https://registry.yarnpkg.com/global-dirs/-/global-dirs-0.1.1.tgz#b319c0dd4607f353f3be9cca4c72fc148c49f445"
@@ -4057,6 +4149,11 @@ globals@^11.1.0, globals@^11.7.0:
40574149
resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"
40584150
integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==
40594151

4152+
globals@^9.18.0:
4153+
version "9.18.0"
4154+
resolved "https://registry.yarnpkg.com/globals/-/globals-9.18.0.tgz#aa3896b3e69b487f17e31ed2143d69a8e30c2d8a"
4155+
integrity sha512-S0nG3CLEQiY/ILxqtztTWH/3iRRdyBLw6KMDxnKMchrtbj2OFmehVh0WUCfW3DUrIgx/qFrJPICrq4Z4sTR9UQ==
4156+
40604157
globby@^6.1.0:
40614158
version "6.1.0"
40624159
resolved "https://registry.yarnpkg.com/globby/-/globby-6.1.0.tgz#f5a6d70e8395e21c858fb0489d64df02424d506c"
@@ -4092,6 +4189,11 @@ graceful-fs@^4.1.6:
40924189
version "4.1.11"
40934190
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658"
40944191

4192+
graceful-fs@^4.2.0:
4193+
version "4.2.0"
4194+
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.0.tgz#8d8fdc73977cb04104721cb53666c1ca64cd328b"
4195+
integrity sha512-jpSvDPV4Cq/bgtpndIWbI5hmYxhQGHPC4d4cqBPb4DLniCfhJokdXhwhaDuLBGLQdvvRum/UiX6ECVIPvDXqdg==
4196+
40954197
growly@^1.3.0:
40964198
version "1.3.0"
40974199
resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081"
@@ -5675,7 +5777,7 @@ lodash.uniq@^4.5.0:
56755777
version "4.5.0"
56765778
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
56775779

5678-
lodash@4.17.11, lodash@^4.17.11, lodash@^4.17.5:
5780+
lodash@4.17.11, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.17.5:
56795781
version "4.17.11"
56805782
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz#b39ea6229ef607ecd89e2c8df12536891cac9b8d"
56815783
integrity sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==
@@ -5759,6 +5861,13 @@ make-dir@^2.0.0, make-dir@^2.1.0:
57595861
pify "^4.0.1"
57605862
semver "^5.6.0"
57615863

5864+
make-dir@^3.0.0:
5865+
version "3.0.0"
5866+
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.0.0.tgz#1b5f39f6b9270ed33f9f054c5c0f84304989f801"
5867+
integrity sha512-grNJDhb8b1Jm1qeqW5R/O63wUo4UXo2v2HMic6YT9i/HBlF93S8jkMgH7yugvY9ABDShH4VZMn8I+U8+fCNegw==
5868+
dependencies:
5869+
semver "^6.0.0"
5870+
57625871
makeerror@1.0.x:
57635872
version "1.0.11"
57645873
resolved "https://registry.yarnpkg.com/makeerror/-/makeerror-1.0.11.tgz#e01a5c9109f2af79660e4e8b9587790184f5a96c"
@@ -7647,6 +7756,11 @@ schema-utils@^1.0.0:
76477756
ajv-errors "^1.0.0"
76487757
ajv-keywords "^3.1.0"
76497758

7759+
scriptjs@^2.5.9:
7760+
version "2.5.9"
7761+
resolved "https://registry.yarnpkg.com/scriptjs/-/scriptjs-2.5.9.tgz#343915cd2ec2ed9bfdde2b9875cd28f59394b35f"
7762+
integrity sha512-qGVDoreyYiP1pkQnbnFAUIS5AjenNwwQBdl7zeos9etl+hYKWahjRTfzAZZYBv5xNHx7vNKCmaLDQZ6Fr2AEXg==
7763+
76507764
select-hose@^2.0.0:
76517765
version "2.0.0"
76527766
resolved "https://registry.yarnpkg.com/select-hose/-/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca"
@@ -7951,6 +8065,11 @@ source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.1:
79518065
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
79528066
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
79538067

8068+
source-map@^0.7.3:
8069+
version "0.7.3"
8070+
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.3.tgz#5302f8169031735226544092e64981f751750383"
8071+
integrity sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==
8072+
79548073
spawn-sync@^1.0.15:
79558074
version "1.0.15"
79568075
resolved "https://registry.yarnpkg.com/spawn-sync/-/spawn-sync-1.0.15.tgz#b00799557eb7fb0c8376c29d44e8a1ea67e57476"
@@ -8457,6 +8576,11 @@ to-arraybuffer@^1.0.0:
84578576
resolved "https://registry.yarnpkg.com/to-arraybuffer/-/to-arraybuffer-1.0.1.tgz#7d229b1fcc637e466ca081180836a7aabff83f43"
84588577
integrity sha1-fSKbH8xjfkZsoIEYCDanqr/4P0M=
84598578

8579+
to-fast-properties@^1.0.3:
8580+
version "1.0.3"
8581+
resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47"
8582+
integrity sha1-uDVx+k2MJbguIxsG46MFXeTKGkc=
8583+
84608584
to-fast-properties@^2.0.0:
84618585
version "2.0.0"
84628586
resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-2.0.0.tgz#dc5e698cbd079265bc73e0377681a4e4e83f616e"
@@ -8890,6 +9014,22 @@ webpack-dev-server@^3.3.1:
88909014
webpack-log "^2.0.0"
88919015
yargs "12.0.5"
88929016

9017+
webpack-external-import@^0.0.1-beta.15:
9018+
version "0.0.1-beta.15"
9019+
resolved "https://registry.yarnpkg.com/webpack-external-import/-/webpack-external-import-0.0.1-beta.15.tgz#5ab74789f6eff17645bc13493c69a372cb9dbf3d"
9020+
integrity sha512-dN+lowZoeBf1y4sr4CaJa5qZWnNFxo8R0lj8jpq7YZlz6ME0ZG2K2g+GxBHzSeFeCop1gCNqTd/sa943mm0toQ==
9021+
dependencies:
9022+
"@babel/helper-module-imports" "^7.0.0"
9023+
babel-traverse "^6.26.0"
9024+
babylon "^6.18.0"
9025+
cacache "^11.3.2"
9026+
find-cache-dir "^3.0.0"
9027+
fs-extra "^8.0.1"
9028+
jest-haste-map "^24.8.0"
9029+
jest-resolve "^24.8.0"
9030+
scriptjs "^2.5.9"
9031+
source-map "^0.7.3"
9032+
88939033
webpack-log@^2.0.0:
88949034
version "2.0.0"
88959035
resolved "https://registry.yarnpkg.com/webpack-log/-/webpack-log-2.0.0.tgz#5b7928e0637593f119d32f6227c1e0ac31e1b47f"

0 commit comments

Comments
 (0)