Skip to content

Commit 6e95020

Browse files
authored
fix: measure uncached positioned ancestors when removing table rows (#249)
* test: cover removing animating table rows in WebKit * fix: measure uncached positioned ancestors during removal * test: reduce table removal coverage to the minimal regression
1 parent 06882a8 commit 6e95020

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

‎src/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ function deletePosition(
823823
const parentCoords =
824824
!animations.has(el) || animations.get(el)?.playState === "finished"
825825
? getCoords(offsetParent)
826-
: coords.get(offsetParent)!
826+
: coords.get(offsetParent) ?? getCoords(offsetParent)
827827

828828
const top =
829829
Math.round(oldCoords.top - parentCoords.top) -

‎tests/e2e/removal-position.spec.ts‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { test, expect } from '@playwright/test'
2+
import { fileURLToPath } from 'node:url'
3+
4+
const fixtureUrl = `/@fs${fileURLToPath(new URL('../fixtures/removal.html', import.meta.url))}`
5+
const moduleUrl = `/@fs${fileURLToPath(new URL('../../src/index.ts', import.meta.url))}`
6+
7+
test('removes a table row during its entry animation', async ({ page }) => {
8+
const errors: string[] = []
9+
page.on('pageerror', error => errors.push(error.message))
10+
await page.goto(fixtureUrl)
11+
await page.evaluate(async moduleUrl => {
12+
const { default: autoAnimate } = await import(moduleUrl)
13+
const rows = document.querySelector('tbody')!
14+
autoAnimate(rows)
15+
const row = rows.insertRow()
16+
row.id = 'removed'
17+
row.insertCell().textContent = 'Remove this row'
18+
}, moduleUrl)
19+
await page.waitForFunction(() =>
20+
document.querySelector('#removed')!.getAnimations().some(a => a.playState === 'running')
21+
)
22+
const wasAnimating = await page.locator('#removed').evaluate(async row => {
23+
const running = row.getAnimations().some(a => a.playState === 'running')
24+
row.remove()
25+
await new Promise(requestAnimationFrame)
26+
return running
27+
})
28+
expect(wasAnimating).toBe(true)
29+
expect(errors).toEqual([])
30+
await expect(page.locator('#removed')).toHaveCount(0)
31+
await expect(page.locator('#survivor')).toHaveCount(1)
32+
})

‎tests/fixtures/removal.html‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head><meta charset="utf-8"><title>Table row removal</title></head>
4+
<body>
5+
<div style="position: relative">
6+
<table>
7+
<tbody><tr id="survivor"><td>Keep this row</td></tr></tbody>
8+
</table>
9+
</div>
10+
</body>
11+
</html>

0 commit comments

Comments
 (0)