-
Notifications
You must be signed in to change notification settings - Fork 174
fix(widget): add iframe loading retry logic #7636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
2476c83
fix: fix widget retry logic
Danziger debf435
Merge branch 'develop' into feat/fix-widget-retry-logic
Danziger 18a7631
Merge branch 'develop' into feat/fix-widget-retry-logic
Danziger 167870f
Merge branch 'develop' into feat/fix-widget-retry-logic
Danziger 158a172
Merge branch 'develop' into feat/fix-widget-retry-logic
fairlighteth 8a63567
Merge branch 'develop' into feat/fix-widget-retry-logic
fairlighteth afba401
Merge branch 'develop' into feat/fix-widget-retry-logic
elena-zh 8bf7e8e
docs: spec for CSP-safe widget error UI
shoom3301 e99f863
feat(widget): refactor widget loading error
shoom3301 5d9982a
feat(widget): restyle widget loading
shoom3301 3fa32c7
fix: pass onLoadingError from CowSwapWidget
shoom3301 e988bb3
chore: remove docs
shoom3301 02edf78
chore: add localStorageOverride WIDGET_BASE_URL
shoom3301 fd753b5
docs: design for rootStyle rename (iframeStyle -> rootStyle on contai…
shoom3301 cfff9c3
docs: implementation plan for rootStyle rename
shoom3301 c06da84
feat(widget)!: rename iframeStyle to rootStyle and apply it to the co…
shoom3301 8ae14af
refactor(widget-configurator): rename iframeStyle to rootStyle
shoom3301 69c5025
refactor(widget-configurator): rename iframe-styles UI copy to root
shoom3301 da91023
chore: changeset for rootStyle rename
shoom3301 2ad4ce9
chore: remove docs
shoom3301 869c4c6
Merge branch 'develop' into feat/fix-widget-retry-logic
shoom3301 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,80 @@ | ||
| /** | ||
| * @jest-environment jsdom | ||
| */ | ||
|
|
||
| import { widgetIframeLoading } from './widgetIframeLoading' | ||
|
|
||
| const ERROR_CLASS = 'cow-widget-loading-error' | ||
| const WIDGET_ORIGIN = 'https://swap.cow.fi' | ||
|
|
||
| type LoadingState = ReturnType<typeof widgetIframeLoading> | ||
|
|
||
| const activeStates: LoadingState[] = [] | ||
|
|
||
| describe('widgetIframeLoading error UI styling', () => { | ||
| beforeEach(() => { | ||
| // The iframe `error` handler logs intentionally; keep test output pristine. | ||
| jest.spyOn(console, 'error').mockImplementation(() => void 0) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| activeStates.splice(0).forEach((state) => state.cancelWidgetLoading()) | ||
| document.body.innerHTML = '' | ||
| document.head.querySelectorAll(`style[data-${ERROR_CLASS}]`).forEach((el) => el.remove()) | ||
| jest.restoreAllMocks() | ||
| }) | ||
|
|
||
| it('renders the error container with its class', () => { | ||
| const { container, iframe } = setup() | ||
|
|
||
| failIframe(iframe) | ||
|
|
||
| const errorEl = container.querySelector<HTMLElement>(`.${ERROR_CLASS}`) | ||
| expect(errorEl).not.toBeNull() | ||
| }) | ||
|
|
||
| it('injects the default error styles for the container and its children', () => { | ||
| const { iframe } = setup() | ||
|
|
||
| failIframe(iframe) | ||
|
|
||
| const style = document.head.querySelector(`style[data-${ERROR_CLASS}]`) | ||
| expect(style).not.toBeNull() | ||
| expect(style?.textContent).toContain(`.${ERROR_CLASS}`) | ||
| expect(style?.textContent).toContain(`.${ERROR_CLASS} button`) | ||
| expect(style?.textContent).toContain(`.${ERROR_CLASS} p`) | ||
| }) | ||
|
|
||
| it('injects the default error styles at most once across repeated failures', () => { | ||
| const first = setup() | ||
| failIframe(first.iframe) | ||
|
|
||
| const second = setup() | ||
| failIframe(second.iframe) | ||
|
|
||
| expect(document.head.querySelectorAll(`style[data-${ERROR_CLASS}]`).length).toBeLessThanOrEqual(1) | ||
| }) | ||
| }) | ||
|
|
||
| function setup(): { container: HTMLElement; iframe: HTMLIFrameElement; state: LoadingState } { | ||
| const container = document.createElement('div') | ||
| document.body.appendChild(container) | ||
|
|
||
| const iframe = document.createElement('iframe') | ||
| iframe.src = `${WIDGET_ORIGIN}/` | ||
| container.appendChild(iframe) | ||
|
|
||
| const state = widgetIframeLoading( | ||
| container, | ||
| iframe, | ||
| () => void 0, | ||
| () => void 0, | ||
| ) | ||
| activeStates.push(state) | ||
|
|
||
| return { container, iframe, state } | ||
| } | ||
|
|
||
| function failIframe(iframe: HTMLIFrameElement): void { | ||
| iframe.dispatchEvent(new Event('error')) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Since the loading error DOM is on the host side, they can style it using css selector
.cow-widget-loading-error