Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: e96777bc779f4bfdda0cc829989bed15720e89ce
      
https://github.com/WebKit/WebKit/commit/e96777bc779f4bfdda0cc829989bed15720e89ce
  Author: Alan Baradlay <[email protected]>
  Date:   2026-04-07 (Tue, 07 Apr 2026)

  Changed paths:
    M LayoutTests/TestExpectations
    A 
LayoutTests/imported/w3c/web-platform-tests/css/css-pseudo/first-letter-float-insert-text-before-expected.html
    A 
LayoutTests/imported/w3c/web-platform-tests/css/css-pseudo/first-letter-float-insert-text-before-ref.html
    A 
LayoutTests/imported/w3c/web-platform-tests/css/css-pseudo/first-letter-float-insert-text-before.html
    A 
LayoutTests/imported/w3c/web-platform-tests/css/css-pseudo/first-letter-insert-text-before-expected.html
    A 
LayoutTests/imported/w3c/web-platform-tests/css/css-pseudo/first-letter-insert-text-before-ref.html
    A 
LayoutTests/imported/w3c/web-platform-tests/css/css-pseudo/first-letter-insert-text-before.html
    M Source/WebCore/rendering/updating/RenderTreeBuilderFirstLetter.cpp

  Log Message:
  -----------
  Inserting a text node before ::first-letter renders the text in the wrong 
order
https://bugs.webkit.org/show_bug.cgi?id=15602
<rdar://171649994>

Reviewed by Antti Koivisto and Tim Nguyen.

Given <div>BC</div> with div::first-letter, WebKit splits the text into
two renderers: first-letter "B" and remaining fragment "C".

When JS inserts a new text node "A" before "BC", the first letter of the
block changes from "B" to "A". But the render tree still has the old
first-letter "B" inline as the first child of the block. The new "A"
renderer ends up after it, so the page shows "BAC" instead of "ABC".

The render tree builder misses this because firstLetterAndContainer walks
the render tree (not the DOM) and finds the old first-letter "B" first.
It assumes the first-letter is still valid and only updates its style.

The fix: when an existing first-letter is found, check if a new text node
was inserted before the first-letter's text node in the DOM. If so, reset
the remaining fragment to its full text (which tears down the stale
first-letter inline via setTextInternal), then let createRenderers rebuild
the first-letter split from the actual first text.

* LayoutTests/TestExpectations:
* 
LayoutTests/imported/w3c/web-platform-tests/css/css-pseudo/first-letter-float-insert-text-before-expected.html:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/css/css-pseudo/first-letter-float-insert-text-before-ref.html:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/css/css-pseudo/first-letter-float-insert-text-before.html:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/css/css-pseudo/first-letter-insert-text-before-expected.html:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/css/css-pseudo/first-letter-insert-text-before-ref.html:
 Added.
* 
LayoutTests/imported/w3c/web-platform-tests/css/css-pseudo/first-letter-insert-text-before.html:
 Added.
* Source/WebCore/rendering/updating/RenderTreeBuilderFirstLetter.cpp:
(WebCore::RenderTreeBuilder::FirstLetter::updateAfterDescendants):

Canonical link: https://commits.webkit.org/310719@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to