Skip to content

fix: preserve -webkit-box display so -webkit-line-clamp survives cloning - #172

Open
razchiriac wants to merge 1 commit into
qq15725:mainfrom
razchiriac:fix/preserve-line-clamp
Open

fix: preserve -webkit-box display so -webkit-line-clamp survives cloning#172
razchiriac wants to merge 1 commit into
qq15725:mainfrom
razchiriac:fix/preserve-line-clamp

Conversation

@razchiriac

Copy link
Copy Markdown

Fixes #121.

Root cause

Chromium reports the computed display of a display: -webkit-box element as flow-root while -webkit-line-clamp is actively clamping it. copyCssStyles copies that computed value inline onto the clone, which drops the legacy box formatting context that -webkit-line-clamp requires — so multi-line ellipsis renders unclamped (or clipped without the ellipsis) in the output image. -webkit-line-clamp and -webkit-box-orient themselves are enumerated and copied correctly; only display is mutated.

Measured in headless Chromium: live clamped element 40px; clone rebuilt from enumerated computed styles 80px (unclamped); clone with display: -webkit-box restored 40px again. This confirms the diagnosis @zstings posted on #121.

Change

In the existing IN_CHROME fix block of copyCssStyles (next to the text-overflow workaround): when the diffed style has display: flow-root, -webkit-box-orient: vertical, and an active -webkit-line-clamp, restore display: -webkit-box on the clone.

We've been running the equivalent repair in production for months while capturing full-page screenshots of a dashboard-style web app.

Test

New fixture test/fixtures/css.-webkit-line-clamp.html + reference snapshot. With the fix the capture shows exactly two lines ending in ; without it, the ellipsis is lost and text is clipped mid-word. Full suite passes (34/34; the pre-existing environment-dependent snapshot warnings are unchanged vs main).

Known limitations

  • display: -webkit-inline-box computes to inline-block and can't be safely rewritten back (rewriting every inline-block would be far too aggressive) — inline clamping remains broken as before.
  • An element that literally specifies display: flow-root together with -webkit-box-orient: vertical and -webkit-line-clamp (a combination that does not clamp live) would be clamped in the clone. This seems pathological enough to accept; distinguishing it would require reading specified (not computed) style.
  • With includeStyleProperties, callers must include display, -webkit-box-orient, and -webkit-line-clamp for the fix to apply.

Chromium reports the computed `display` of a `display: -webkit-box`
element as `flow-root` while `-webkit-line-clamp` is clamping it.
copyCssStyles copied that computed value onto the clone, which dropped
the legacy box layout, so multi-line ellipsis rendered unclamped or
clipped without the ellipsis in the output image.

When the computed style carries `-webkit-box-orient: vertical` and an
active `-webkit-line-clamp`, restore `display: -webkit-box` on the
clone. Chromium-only, like the neighboring text-overflow fix.

Fixes qq15725#121
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

css 设置多行文本省略 无效

2 participants