Skip to content

[lexical-playground] Bug Fix: clear Card/Review CSS placeholders reliably on paste in Safari - #9129

Merged
etrepum merged 1 commit into
meta:mainfrom
sahiee-dev:fix/safari-slot-placeholder-has-invalidation
Sep 8, 2026
Merged

etrepum merged 1 commit into
meta:mainfrom
sahiee-dev:fix/safari-slot-placeholder-has-invalidation

Conversation

@sahiee-dev

Copy link
Copy Markdown
Contributor

Description

When pasting text into an empty Card title or body field, or into an empty Review author or prose field, the CSS ::before placeholder (Title, Body, Author, or Write 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-child pseudo-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:

:has(br:only-child)

to:

:has(> br):not(:has(> * + *))

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

…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.
@vercel

vercel Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
lexical Ready Ready Preview Sep 7, 2026 6:35pm UTC
lexical-playground Ready Ready Preview Sep 7, 2026 6:35pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 7, 2026

@etrepum etrepum left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Sep 7, 2026
@levensta

levensta commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

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

@etrepum

etrepum commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

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.

@etrepum

etrepum commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

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 etrepum left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@etrepum
etrepum added this pull request to the merge queue Sep 8, 2026
Merged via the queue into meta:main with commit f292965 Sep 8, 2026
54 checks passed
@etrepum etrepum mentioned this pull request Sep 17, 2026

This branch was successfully deployed

2 active deployments
Preview – lexical — f1d2cd78 Deployed Sep 7, 2026 by vercel[bot]
Preview – lexical-playground — f1d2cd78 Deployed Sep 7, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Placeholder still displays when pasting text in Safari

3 participants