ampproject / ampproject/worker-dom

Failure to addEventListener after awaiting getBoundingClientRectAsync

Open
#612 0 comments 0 reactions 1 assignee Claimed by @kristoferbaxter View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.