Repository navigation
[lexical-playground] Bug Fix: clear Card/Review CSS placeholders reliably on paste in Safari - #9129
Conversation
…ably on paste in Safari
## Description
Pasting text into an empty Card title/body field, or an empty Review
author/prose field, left the CSS `::before` placeholder ("Title", "Body",
"Author", "Write a review…") rendered on top of the pasted text in Safari,
until an unrelated forced repaint (e.g. zooming) cleared it. Typing the
same content character-by-character was unaffected.
The placeholders detect an empty field with `:has(br:only-child)`, matching
the reconciler's own empty-state `<br>`. WebKit fails to invalidate a
`:has()` selector whose argument nests a sibling-count pseudo-class
(`:only-child`) across the insert-then-remove-in-one-pass DOM mutation the
reconciler always performs when a field goes from empty to non-empty on
paste — the placeholder's matched state goes stale until something else
forces a style recalculation. Typing doesn't hit the same reconciliation
ordering, so it was unaffected.
This replaces the four affected selectors (Card title, Card body, Review
author, Review prose) with `:has(> br):not(:has(> * + *))`, an equivalent
check ("the paragraph's only element child is a `<br>`") that sidesteps the
WebKit invalidation bug without matching a real `<br>` from a user's
Shift+Enter line break.
Closes meta#9126
## Test plan
### Before
Command: `E2E_BROWSER=webkit npx playwright test --project=webkit -g "9126" packages/lexical-playground/__tests__/e2e/CardSlot.spec.mjs`
New regression tests, run against the unpatched `:has(br:only-child)` selector:
```
✘ pasting text into an empty title clears its placeholder immediately (meta#9126)
✘ pasting text into an empty body clears its placeholder immediately (meta#9126)
Error: expect(received).toBe(expected) // Object.is equality
Expected: true
Received: false
```
### After
Command: `E2E_BROWSER=webkit npx playwright test --project=webkit packages/lexical-playground/__tests__/e2e/CardSlot.spec.mjs packages/lexical-playground/__tests__/e2e/ReviewSlot.spec.mjs`
```
36 passed (46.6s)
```
Same suite on Chromium as a control (was never affected): `36 passed (35.5s)`.
Also verified: `pnpm run tsc`, `pnpm run flow`, `pnpm run prettier`, `pnpm run lint` all clean; `pnpm run test-unit` — 6133 passed, 1 skipped.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
left a comment
There was a problem hiding this comment.
I don’t think these tests are going to do anything useful, the bug is a display issue in Safari that isn’t going to show up in the DOM
|
In actually with this bug the pseudo-element does remain in the DOM and disappears after a repaint _Screen.Recording.2026-09-08.at.01.04.22.mov |
|
Yeah sure but pseudo-elements don’t have a DOM representation so you can’t find them with querySelector, only target them with CSS, which is mostly only observable visually when it’s not working correctly. |
|
Unless the test is visually confirming that the render is correct then the test is providing negative value because it is just running code that would be true with or without the patch. |
etrepum
left a comment
There was a problem hiding this comment.
After a closer review and local testing it looks like this testing strategy does successfully detect the Safari bug, so we can keep them as-is
Description
When pasting text into an empty Card title or body field, or into an empty Review author or prose field, the CSS
::beforeplaceholder (Title,Body,Author, orWrite a review…) could remain visible on top of the pasted text in Safari.The placeholder would only disappear after an unrelated action caused a repaint, such as zooming the page. Typing the same content character-by-character did not reproduce the issue.
The affected placeholders use
:has(br:only-child)to detect an empty field. This matches the<br>that the reconciler inserts to represent an empty paragraph.The issue appears to be a WebKit invalidation bug. When pasting into an empty field, the reconciler performs an insert-and-remove DOM mutation in a single pass. WebKit fails to properly invalidate the
:has()selector when its argument contains the:only-childpseudo-class, leaving the placeholder's matched state stale until another style recalculation is triggered.Typing doesn't follow the same reconciliation path, which is why it wasn't affected.
Fix
The four affected selectors (Card title, Card body, Review author, and Review prose) have been updated from:
to:
This is equivalent to checking that the paragraph contains a
<br>and that it has no other element children — effectively, that the<br>is the paragraph's only element child.The new selector also avoids treating a real
<br>created by a user's Shift+Enter as an empty field.Closes #9126.
Test Plan
Before
Screen.Recording.2026-09-07.at.12.25.39.PM.mov
After
Screen.Recording.2026-09-07.at.12.26.24.PM.mov