-
Notifications
You must be signed in to change notification settings - Fork 248
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
fix: avoid throwing errors if container is no longer in page #424
fix: avoid throwing errors if container is no longer in page #424
Conversation
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.
I haven't looked into testing in Zoid so I don't know how reasonable this ask is: can we write a test for this?
I agree that it would be awesome to add a couple tests to cover this new logic. I'm really excited about this improvement. Great work so far @oscarleonnogales! |
This is great, thanks everyone! |
Codecov ReportPatch coverage:
📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more Additional details and impacted files@@ Coverage Diff @@
## main #424 +/- ##
==========================================
+ Coverage 95.63% 95.65% +0.02%
==========================================
Files 18 18
Lines 1213 1221 +8
==========================================
+ Hits 1160 1168 +8
Misses 53 53
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
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.
This looks great to me! Nice work @oscarleonnogales 💯
it("should error out where the domain is an invalid regex", () => { | ||
return wrapPromise(({ expect }) => { | ||
window.__component__ = () => { | ||
return zoid.create({ | ||
tag: "test-render-domain-invalid-regex", | ||
url: "mock://www.child.com/base/test/windows/child/index.htm", | ||
domain: /^mock:\/\/www\.meep\.com$/, | ||
}); | ||
}; | ||
|
||
const component = window.__component__(); | ||
return component({ | ||
onDestroy: expect("onDestroy"), | ||
}) | ||
.render(getBody()) | ||
.catch(expect("catch")); | ||
}); | ||
}); | ||
|
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.
Removing this test because we aren't explicitly checking for valid regex inside of zoid.
The getDomain
function already has proper error handling and checking in the cross-domain-utils repository.
Looks great man 🔥 Love that you moved the error messages into a const ⚡️ |
src/parent/parent.js
Outdated
context === CONTEXT.IFRAME && | ||
isClosed && | ||
((currentContainer && isElementClosed(currentContainer)) || | ||
isSecondRenderFinished) |
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.
where did we land on checking for second render? I thought we said this might cause weird issues but I don't remember if we changed our minds 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.
We did decide to not use the condition of waiting until second render was finished by itself, as that could cause issues when the container is removed for a legitimate reason before it's finished.
Essentially I combined options 1 and 2 and it seemed to work well. If the container is removed, OR second render is finished then we should call close
here.
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.
okay sounds good, thank you!
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.
I am a little worried about adding the new isSecondRenderFinished logic here. The prerender phase still renders inside an <iframe>
with no src tag. If that gets destroyed, we would still want this error to be thrown.
Description
We have identified a few errors that zoid throws that cannot be caught by the implementation code (
render.catch()
andclose.catch()
) during asynchronous dismounts. Although this can occur in every webpage, it's primarily an issue when using React as seen here: Issue #334With this change, we first check if the container element has been removed from the DOM or the user has navigated away from the page mid-render. In these scenarios we should avoid throwing errors.
Here are 3 examples:
https://github.com/krakenjs/zoid/blob/main/src/parent/parent.js#L857
https://github.com/krakenjs/zoid/blob/main/src/parent/parent.js#L826
https://github.com/krakenjs/zoid/blob/main/src/parent/parent.js#L1172
These 3 error flows eventually cause the promise to be rejected since the render was never completed, and an error to be displayed on the console: https://github.com/krakenjs/zoid/blob/main/src/parent/parent.js#L732
Reproduction Steps (if applicable)
To reproduce the
Window navigated away
error, open Chrome developer tools and persist logs. CallpaypalButtons.render('container-selector')
and then refresh the window or navigate to a different URL before second render is finished.To reproduce
Component closed
orDetected container element removed from DOM
, CallpaypalButtons.render('container-selector')
and then immediately remove the container selector before second render is finished.Why are we making these changes? Include references to any related Jira tasks or GitHub Issues
https://paypal.atlassian.net/browse/LI-7432