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
shadowDoc: Return promise from close method #25094
Conversation
The existing shadowDoc.close() method is not fully synchronous. Notably, the 'pass' that occurs on a visibility state change may not complete before additional tasks are performed, like removing the ShadowRoot host completely. Cleanup is incomplete and there are some potentially valuable unload tasks that were not given the chance to run. Expose shadowDoc.closeAsync() method that waits for the next visibility state change pass to complete before resolving.
This commit is most easily tested by combining with PR #25014. |
/cc @dvoytenko |
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.
@dvoytenko: Would it be so bad to add a forced sync unlayoutCallback
to resources? That way everyone always gets the correct behavior, not just the people who call closeAsync
.
I think we just need |
What we found in #25014 (comment) is that calling |
Gathering comments, here are the paths forward I see. I'm interested in hearing which option (or another if you see more options) is preferred. Status
Documentation for
Option 1 Revise The safety check in Option 2 Introduce an optional, fully synchronous path for handling the visibility state transition to |
I don't think Option 2 is feasible, because it would impact the swipe-to-next-doc performance of the SERP carousel. I'd rather the |
@jridgewell that's the user code behavior, right? I think it's ok for many, and otherwise our recommendation should be:
Would that work? |
Yes, that'll work. My preference would still be do to the bug-free thing by default, but I'm fine with just returning a promise. |
I'm not completely sure I know where you two landed. Do your expectations match everything I wrote in Option 1 above? Namely, is introducing |
@jridgewell @dvoytenko I didn't hear back from you guys on my last comment, so I made revisions to the best of my understanding of your requests. Please let me know if the current version of this PR matches your expected behavior. Thanks! |
Codecov Report
@@ Coverage Diff @@
## master #25094 +/- ##
==========================================
- Coverage 79.79% 79.74% -0.06%
==========================================
Files 855 853 -2
Lines 52162 51905 -257
==========================================
- Hits 41624 41392 -232
+ Misses 10538 10513 -25
Continue to review full report at Codecov.
|
Ping @dvoytenko |
LGTM |
* shadowDoc: Expose async close method The existing shadowDoc.close() method is not fully synchronous. Notably, the 'pass' that occurs on a visibility state change may not complete before additional tasks are performed, like removing the ShadowRoot host completely. Cleanup is incomplete and there are some potentially valuable unload tasks that were not given the chance to run. Expose shadowDoc.closeAsync() method that waits for the next visibility state change pass to complete before resolving. * Add shadowDoc.closeAsync to documentation * Prefer service/timer promise race method * Avoid race between resources promise and cleanup * Revisions based on feedback * Backwards-compatible shadow close and update unit tests * Fix comment, remove examples * Another shot at fixing the comment
The existing
shadowDoc.close()
method is not fully synchronous. Notably,the
pass
that occurs on a visibility state change may not completebefore additional tasks are performed, like removing the
ShadowRoot
hostcompletely. Cleanup is incomplete and there are some potentially
valuable unload tasks that were not given the chance to run. Return a promise
from
shadowDoc.close()
that resolves when the next visibility state changecompletes after requesting a change to
INACTIVE
.