fix: Explicitly handle null attribute values (#1157)

* fix: Explicitly handle removed attributes

The attribute `value` can be null when a mutation observer triggers due to a removed attribute. This is currently not reflected by types and code.

* Apply formatting changes

* fix

* add changeset
This commit is contained in:
Francesco Novy
2026-04-01 12:00:00 +08:00
committed by GitHub
parent 7dca0f37c4
commit 8b55751a40
7 changed files with 256 additions and 15 deletions

View File

@@ -141,6 +141,32 @@ describe('record integration tests', function (this: ISuite) {
assertSnapshot(snapshots);
});
it('handles null attribute values', async () => {
const page: puppeteer.Page = await browser.newPage();
await page.goto('about:blank');
await page.setContent(getHtml.call(this, 'mutation-observer.html', {}));
await page.evaluate(() => {
const li = document.createElement('li');
const ul = document.querySelector('ul') as HTMLUListElement;
ul.appendChild(li);
li.setAttribute('aria-label', 'label');
li.setAttribute('id', 'test-li');
});
await new Promise((resolve) => setTimeout(resolve, 100));
await page.evaluate(() => {
const li = document.querySelector('#test-li') as HTMLLIElement;
// This triggers the mutation observer with a `null` attribute value
li.removeAttribute('aria-label');
});
const snapshots = await page.evaluate('window.snapshots');
assertSnapshot(snapshots);
});
it('can record node mutations', async () => {
const page: puppeteer.Page = await browser.newPage();
await page.goto('about:blank');