-
Notifications
You must be signed in to change notification settings - Fork 36
Fix client-side onerror handling no working due to missing crossorigin attribute for CDN scripts #764
base: master
Are you sure you want to change the base?
Conversation
| 'one extra script after loading new route' | ||
| ); | ||
|
|
||
| t.ok( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason this crossorigin logic exists is because of:
webpack/webpack#6972 (comment)
So this test is verifying that when not using a CDN, no crossorigin attributes are set. I don't think we want to delete these tests. I think this test should remain unchanged.
Instead, there are tests that do use a CDN, and we should verify that crossorigin attributes are set. As you point out, these assertions would probably currently fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added tests for CDN case if we want to go that route.
plugins/ssr-plugin.js
Outdated
| let preloadHints = []; | ||
|
|
||
| for (let url of criticalChunkUrls) { | ||
| const crossoriginAttr = url.startsWith(__webpack_public_path__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I'm thinking that this condition might not be the correct thing to check against, since __webpack_public_path__ could be a CDN. Perhaps it should be url.startsWith("/"), but I suppose that doesn't handle the case where the absolute url is same-origin (although this case might not matter in practice).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the legacy ssr template used webpackPublicPath.startsWith('http') which is similar to what you mentioned. What about checking forCDN_URL?
const crossoriginAttr = process.env.CDN_URL ? ' crossorigin="anonymous"' : '';bdbc84f to
85918ca
Compare
85918ca to
5f6b943
Compare
Couple things to note:
__webpack_public_path__but not sure if it should always be set for "critical chunk" scripts.el.crossOrigin === 'anonymous'was failing so I'm assuming there are other scripts.