-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): CHECKOUT-4455 Provide fallback for browsers that don't sup…
…port `preload` attribute
- Loading branch information
Showing
11 changed files
with
286 additions
and
76 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import BrowserSupport from './browser-support'; | ||
|
||
describe('BrowserSupport', () => { | ||
let link: HTMLLinkElement; | ||
let support: BrowserSupport; | ||
|
||
beforeEach(() => { | ||
const createElement = document.createElement.bind(document); | ||
|
||
link = { | ||
relList: { | ||
supports: jest.fn(() => true), | ||
}, | ||
} as unknown as HTMLLinkElement; | ||
|
||
jest.spyOn(document, 'createElement') | ||
.mockImplementation(type => { | ||
return type === 'link' ? link : createElement(type); | ||
}); | ||
|
||
support = new BrowserSupport(); | ||
}); | ||
|
||
it('returns true if able to support rel type', () => { | ||
expect(support.canSupportRel('preload')) | ||
.toEqual(true); | ||
}); | ||
|
||
it('returns false if unable to support rel type', () => { | ||
jest.spyOn(link.relList, 'supports') | ||
.mockReturnValue(false); | ||
|
||
expect(support.canSupportRel('preload')) | ||
.toEqual(false); | ||
}); | ||
|
||
it('returns false if `relList` is not supported', () => { | ||
link = {} as unknown as HTMLLinkElement; | ||
|
||
expect(support.canSupportRel('preload')) | ||
.toEqual(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export default class BrowserSupport { | ||
canSupportRel(rel: string): boolean { | ||
const link = document.createElement('link'); | ||
|
||
return !!( | ||
link.relList && | ||
link.relList.supports && | ||
link.relList.supports(rel) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
import { createRequestSender } from '@bigcommerce/request-sender'; | ||
|
||
import BrowserSupport from './browser-support'; | ||
import ScriptLoader from './script-loader'; | ||
|
||
export default function createScriptLoader(): ScriptLoader { | ||
return new ScriptLoader(); | ||
return new ScriptLoader( | ||
new BrowserSupport(), | ||
createRequestSender() | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
import { createRequestSender } from '@bigcommerce/request-sender'; | ||
|
||
import BrowserSupport from './browser-support'; | ||
import StylesheetLoader from './stylesheet-loader'; | ||
|
||
export default function createStylesheetLoader(): StylesheetLoader { | ||
return new StylesheetLoader(); | ||
return new StylesheetLoader( | ||
new BrowserSupport(), | ||
createRequestSender() | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
export { default as ScriptLoader } from './script-loader'; | ||
export { default as ScriptLoader, LoadScriptOptions, PreloadScriptOptions } from './script-loader'; | ||
export { default as createScriptLoader } from './create-script-loader'; | ||
export { default as getScriptLoader } from './get-script-loader'; | ||
|
||
export { default as StylesheetLoader } from './stylesheet-loader'; | ||
export { default as StylesheetLoader, LoadStylesheetOptions, PreloadStylesheetOptions } from './stylesheet-loader'; | ||
export { default as createStylesheetLoader } from './create-stylesheet-loader'; | ||
export { default as getStylesheetLoader } from './get-stylesheet-loader'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.