Skip to content

Commit 37902c4

Browse files
[css-view-transitions-1] Fix some promise timing, and avoid duplicate unhandled rejections (#8454)
Fixes #8455
1 parent e7c1c82 commit 37902c4

File tree

1 file changed

+35
-16
lines changed

1 file changed

+35
-16
lines changed

css-view-transitions-1/Overview.bs

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ urlPrefix: https://html.spec.whatwg.org/multipage/rendering.html; type: dfn;
897897
{{UpdateCallback|updateCallback}} is called asynchronously, once the current state of the document is captured.
898898
Then, when the promise returned by {{UpdateCallback|updateCallback}} fulfills, the new state of the document is captured.
899899

900-
{{UpdateCallback|updateCallback}} is _always_ called, even if the transition cannot happen (e.g. due to duplicate `view-transition-name` values).
900+
{{UpdateCallback|updateCallback}} is *always* called, even if the transition cannot happen (e.g. due to duplicate `view-transition-name` values).
901901
The transition is an enhancement around the state change, so a failure to create a transition never prevents the state change.
902902
See [[#transitions-as-enhancements]] for more details on this principle.
903903

@@ -1015,9 +1015,17 @@ urlPrefix: https://html.spec.whatwg.org/multipage/rendering.html; type: dfn;
10151015
:: a {{Promise}}.
10161016
Initially [=a new promise=] in [=this's=] [=relevant Realm=].
10171017

1018+
Note: The [=ready promise=] and [=update callback done promise=] are immediately created,
1019+
so rejections will cause {{unhandledrejection}}s unless they're [=mark as handled|handled=],
1020+
even if the getters such as {{updateCallbackDone}} are not accessed.
1021+
10181022
: <dfn>finished promise</dfn>
10191023
:: a {{Promise}}.
1020-
Initially [=a new promise=] in [=this's=] [=relevant Realm=].
1024+
Initially [=a new promise=] in [=this's=] [=relevant Realm=],
1025+
[=marked as handled=].
1026+
1027+
Note: This is [=marked as handled=] to prevent duplicate {{unhandledrejection}}s,
1028+
as this promise only ever rejects along with the [=update callback done promise=].
10211029

10221030
: <dfn>transition root pseudo-element</dfn>
10231031
:: a ''::view-transition''.
@@ -1135,9 +1143,14 @@ urlPrefix: https://html.spec.whatwg.org/multipage/rendering.html; type: dfn;
11351143

11361144
Note: This happens if |transition| was [=skip the view transition|skipped=] before this point.
11371145

1146+
1. [=Mark as handled=] |transition|'s [=ViewTransition/ready promise=].
1147+
1148+
Note: |transition|'s [=ViewTransition/update callback done promise=] will provide the {{unhandledrejection}}.
1149+
This step avoids a duplicate.
1150+
11381151
1. [=Skip the view transition=] |transition| with |reason|.
11391152

1140-
* If the promise was resolved, then:
1153+
* If the promise was fulfilled, then:
11411154

11421155
1. If |transition|'s [=ViewTransition/phase=] is "`done`", then return.
11431156

@@ -1424,19 +1437,23 @@ urlPrefix: https://html.spec.whatwg.org/multipage/rendering.html; type: dfn;
14241437

14251438
1. [=Assert=]: |transition|'s [=ViewTransition/phase=] is [=phases/before=] "`update-callback-called`".
14261439

1427-
1. Let |callbackPromise| be [=a new promise=] in |transition|'s [=relevant Realm=].
1440+
1. Let |callbackPromise| be null.
14281441

1429-
* If |transition|'s [=ViewTransition/update callback=] is null, then resolve |callbackPromise|.
1442+
1. If |transition|'s [=ViewTransition/update callback=] is null,
1443+
then set |callbackPromise| to [=a promise resolved with=] undefined,
1444+
in |transition|'s [=relevant Realm=].
14301445

1431-
* Otherwise, let |callbackPromise| be the result of [=/invoking=] |transition|'s [=ViewTransition/update callback=].
1446+
1. Otherwise, set |callbackPromise| to the result of [=/invoking=] |transition|'s [=ViewTransition/update callback=].
14321447

14331448
1. Set |transition|'s [=ViewTransition/phase=] to "`update-callback-called`".
14341449

1435-
1. [=promise/React=] to |callbackPromise|:
1450+
1. [=Resolve=] |transition|'s [=ViewTransition/update callback done promise=]
1451+
with the result of [=reacting=] to |callbackPromise|:
14361452

1437-
* If |callbackPromise| was resolved, then [=resolve=] |transition|'s [=ViewTransition/update callback done promise=].
1453+
- If the promise was fulfilled, then return undefined.
14381454

1439-
* If |callbackPromise| was rejected with reason |r|, then [=reject=] |transition|'s [=ViewTransition/update callback done promise=] with |r|.
1455+
Note: Since the rejection of |callbackPromise| isn't explicitly handled here,
1456+
if |callbackPromise| rejects, then |transition|'s [=ViewTransition/update callback done promise=] will reject with the same reason.
14401457
</div>
14411458

14421459
## [=Skip the view transition=] ## {#skip-the-view-transition-algorithm}
@@ -1458,17 +1475,19 @@ urlPrefix: https://html.spec.whatwg.org/multipage/rendering.html; type: dfn;
14581475

14591476
1. Set |transition|'s [=ViewTransition/phase=] to "`done`".
14601477

1461-
1. If |transition|'s [=ViewTransition/ready promise=] has not yet been resolved, [=reject=] it with |reason|.
1478+
1. [=Reject=] |transition|'s [=ViewTransition/ready promise=] with |reason|.
14621479

1463-
Note: The ready promise would've been resolved if {{ViewTransition/skipTransition()}} is called after we start animating.
1480+
Note: The [=ViewTransition/ready promise=] may already be resolved at this point,
1481+
if {{ViewTransition/skipTransition()}} is called after we start animating.
1482+
In that case, this step is a no-op.
14641483

1465-
1. [=promise/React=] to |transition|'s [=ViewTransition/update callback done promise=]:
1484+
1. [=Resolve=] |transition|'s [=ViewTransition/finished promise=] with the result of [=reacting=] to |transition|'s [=ViewTransition/update callback done promise=]:
14661485

1467-
* If |transition|'s [=ViewTransition/update callback done promise=] was resolved,
1468-
then [=resolve=] |transition|'s [=ViewTransition/finished promise=].
1486+
- If the promise was fulfilled, then return undefined.
14691487

1470-
* If |transition|'s [=ViewTransition/update callback done promise=] was rejected with reason |reason|,
1471-
then [=reject=] |transition|'s [=ViewTransition/finished promise=] with |reason|.
1488+
Note: Since the rejection of |transition|'s [=ViewTransition/update callback done promise=] isn't explicitly handled here,
1489+
if |transition|'s [=ViewTransition/update callback done promise=] rejects,
1490+
then |transition|'s [=ViewTransition/finished promise=] will reject with the same reason.
14721491
</div>
14731492

14741493
## [=Capture the image=] ## {#capture-the-image-algorithm}

0 commit comments

Comments
 (0)