Skip to content
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
16 changes: 3 additions & 13 deletions packages/core/src/app/auto-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export interface CustomCheckoutWindow extends Window {
publicPath?: string;
sentryConfig?: BrowserOptions;
permalinkStatus?: OrderPermalinkStatus | null;
isConsistentCrossOriginFixEnabled?: boolean;
};
}

Expand All @@ -31,18 +30,9 @@ function isCustomCheckoutWindow(window: Window): window is CustomCheckoutWindow
throw new Error('Checkout config is missing.');
}

const { renderOrderConfirmation, renderCheckout } = await loadFiles({
isConsistentCrossOriginFixEnabled: Boolean(
window.checkoutConfig.isConsistentCrossOriginFixEnabled,
),
});

const {
orderId,
checkoutId,
isConsistentCrossOriginFixEnabled: _isConsistentCrossOriginFixEnabled,
...appProps
} = window.checkoutConfig;
const { renderOrderConfirmation, renderCheckout } = await loadFiles();

const { orderId, checkoutId, ...appProps } = window.checkoutConfig;

if (orderId) {
renderOrderConfirmation({ ...appProps, orderId });
Expand Down
28 changes: 4 additions & 24 deletions packages/core/src/app/loader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,44 +119,24 @@ describe('loadFiles', () => {
);
});

it('prefetches dynamic JS chunks listed in manifest', async () => {
it('prefetches dynamic JS chunks with crossorigin matching the real chunk requests', async () => {
await loadFiles(options);

expect(getScriptLoader().preloadScripts).toHaveBeenCalledWith(
['https://cdn.foo.bar/step-a.js', 'https://cdn.foo.bar/step-b.js'],
{ prefetch: true },
{ prefetch: true, crossOrigin: 'anonymous' },
);
});

it('prefetches dynamic CSS chunks listed in manifest', async () => {
it('prefetches dynamic CSS chunks with crossorigin matching the real chunk requests', async () => {
await loadFiles(options);

expect(getStylesheetLoader().preloadStylesheets).toHaveBeenCalledWith(
['https://cdn.foo.bar/step-a.css', 'https://cdn.foo.bar/step-b.css'],
{ prefetch: true },
{ prefetch: true, crossOrigin: 'anonymous' },
);
});

describe('when isConsistentCrossOriginFixEnabled is true', () => {
it('prefetches dynamic JS chunks with crossorigin matching the real chunk requests', async () => {
await loadFiles({ ...options, isConsistentCrossOriginFixEnabled: true });

expect(getScriptLoader().preloadScripts).toHaveBeenCalledWith(
['https://cdn.foo.bar/step-a.js', 'https://cdn.foo.bar/step-b.js'],
{ prefetch: true, crossOrigin: 'anonymous' },
);
});

it('prefetches dynamic CSS chunks with crossorigin matching the real chunk requests', async () => {
await loadFiles({ ...options, isConsistentCrossOriginFixEnabled: true });

expect(getStylesheetLoader().preloadStylesheets).toHaveBeenCalledWith(
['https://cdn.foo.bar/step-a.css', 'https://cdn.foo.bar/step-b.css'],
{ prefetch: true, crossOrigin: 'anonymous' },
);
});
});

it('resolves with app version', async () => {
const result = await loadFiles(options);

Expand Down
4 changes: 1 addition & 3 deletions packages/core/src/app/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export interface AssetManifest {

export interface LoadFilesOptions {
publicPath?: string;
isConsistentCrossOriginFixEnabled?: boolean;
}

export interface LoadFilesResult {
Expand All @@ -32,7 +31,6 @@ export interface LoadFilesResult {

export function loadFiles(options?: LoadFilesOptions): Promise<LoadFilesResult> {
const publicPath = configurePublicPath(options && options.publicPath);
const isConsistentCrossOriginFixEnabled = Boolean(options?.isConsistentCrossOriginFixEnabled);

const {
appVersion,
Expand Down Expand Up @@ -74,7 +72,7 @@ export function loadFiles(options?: LoadFilesOptions): Promise<LoadFilesResult>

const preloadOptions = {
prefetch: true,
...(isConsistentCrossOriginFixEnabled && { crossOrigin: 'anonymous' as const }),
crossOrigin: 'anonymous' as const,
};

getScriptLoader().preloadScripts(
Expand Down