Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Fix client-side onerror handling no working due to missing crossorigin attribute for CDN scripts #764

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions plugins/ssr-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ const SSRBodyTemplate = createPlugin/*:: <SSRBodyTemplateDepsType,SSRBodyTemplat
let preloadHints = [];

for (let url of criticalChunkUrls) {
const crossoriginAttr = url.startsWith(__webpack_public_path__)
? ''
: ' crossorigin="anonymous"';
const crossoriginAttr = process.env.CDN_URL
? ' crossorigin="anonymous"'
: '';
preloadHints.push(
`<link rel="preload" href="${url}" nonce="${
ctx.nonce
Expand Down
37 changes: 37 additions & 0 deletions test/e2e/dynamic-import-app/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,43 @@ test('`fusion build` app with dynamic imports integration', async () => {
proxy.close();
}, 100000);

test('`fusion build` app with CDN_URL and same-origin', async () => {
await cmd(`build --dir=${dir} --production`);

// Run puppeteer test to ensure that page loads with dynamic content.
const {proc, port} = await start(`--dir=${dir}`, {
env: Object.assign({}, process.env, {
CDN_URL: 'https://cdn.com',
NODE_ENV: 'production',
}),
});

const browser = await puppeteer.launch({
args: ['--no-sandbox', '--disable-setuid-sandbox'],
});
const page = await browser.newPage();
await page.setRequestInterception(true);
await page.on('request', request => {
// Ignore CDN requests since they will cause the browser to hang.
if (request.url().startsWith('https://cdn.com')) {
request.abort();
} else {
request.continue();
}
});
await page.goto(`http://localhost:${port}/`, {waitUntil: 'load'});

t.ok(
await page.$$eval('script[src]:not([type="application/json"])', els =>
els.every(el => el.crossOrigin === 'anonymous')
),
'non-module scripts have crossorigin attribute'
);

browser.close();
proc.kill();
}, 100000);

test('`fusion build` app with Safari user agent and same-origin', async () => {
var env = Object.create(process.env);
env.NODE_ENV = 'production';
Expand Down