ampproject / ampproject/worker-dom
Failure to addEventListener after awaiting getBoundingClientRectAsync
- Dominant language
- TypeScript
- Stars
- 3.3k
- Forks
- 154
- PR merge metrics
- No merged PRs in 30d
Description
Consider the two functions:
```js
async function pass() {
document.body.addEventListener( 'click', () => {
console.info( 'Clicked from pass().' );
} );
const rect = await document.body.getBoundingClientRectAsync();
console.info( 'Rect', rect );
}
```
```js
async function fail() {
const rect = await document.body.getBoundingClientRectAsync();
document.body.addEventListener( 'click', () => {
console.info( 'Clicked from fail().' );
} );
console.info( 'Rect', rect );
}
```
They are the same except for the order of when `document.body.addEventListener()` is called vs awaiting `document.body.getBoundingClientRectAsync()`.
In `pass()` where the event listener is added first, there is no problem and the `rect` is logged out.
In `fail()` however, where it first `await`s the bounding rect, there is then a failure when attempting to `addEventListener()`:
> "amp-script" is terminated due to unallowed mutation.
Nevertheless, the `rect` is still logged out, but the `amp-script` is then `i-amphtml-broken`.
Contributor guide
Assessment
This issue has not been assessed yet.