Bug 259188

Summary: "-webkit-box-decoration-break: clone" with left and right padding causes unexpected wrapping of inline content
Product: WebKit Reporter: Pavel Antolík <xtwonine29>
Component: Layout and RenderingAssignee: zalan <zalan>
Status: RESOLVED FIXED    
Severity: Minor CC: bfulgham, koivisto, simon.fraser, webkit-bug-importer, zalan
Priority: P2 Keywords: InRadar
Version: Safari 16   
Hardware: iPhone / iPad   
OS: iOS 16   
URL: https://codepen.io/29pixels/pen/MWzQjXp
Attachments:
Description Flags
photo demonstrating the issue on a physical device with iOS 16.5.1
none
Test reduction
none
[fast-cq]Patch
none
Screenshot with patch applied
none
(iOS screenshot) none

Description Pavel Antolík 2023-07-13 06:55:28 PDT
Created attachment 467032 [details]
photo demonstrating the issue on a physical device with iOS 16.5.1

When using "-webkit-box-decoration-break: clone" in combination with left and right padding, Safari 16 seems to incorrectly determine the inline element's width resulting in unnecessary / unwanted line breaks (even though there is more than enough space for the element). If I set paddings to 0, everything works as expected.

Problem appears to be somewhat tied to the Safari version on physical devices - tried multiple devices but only those with Safari 16 were affected. Funnily enough, in the Simulator the bug didn't manifest at all.

iPhone XR, OS 16.5.1. - issue present
iPhone 6, OS 12.5.7. - everything okay
iPad mini 2, OS 12.5. - everything okay
iPad 7, OS 16.4.1. - issue present

For a visual demonstration, please see the attached photo. It's clearly visible that even though there is enough space on both sides of the inline element, it still gets wrapped in a very unpleasant way.

P.S.: I noticed some other bugreports regarding "webkit-box-decoration-break: clone" but all of them are supposedly fixed already, while this problem I am reporting still persists.
Comment 1 zalan 2023-07-13 07:16:41 PDT
Thank for filing this bug report! Could you attach either a sample test case or the full url to wordbreak.w2.d.webnodev.com where this bug reproduces, please?
Comment 2 Pavel Antolík 2023-07-13 07:22:58 PDT
Hi Zalan, what a ligtning fast response, respect!

As much as I'd love to include the URL with the initial bug spotting, I cannot as it's behind a VPN and inaccessible from the outside.

HOWEVER, I just managed to replicate the issue in codepen, here is the link: https://codepen.io/29pixels/pen/MWzQjXp (I also updated it in the URL field).
Comment 3 zalan 2023-07-13 07:27:55 PDT
(In reply to Pavel Antolík from comment #2)
> Hi Zalan, what a ligtning fast response, respect!
:)

> 
> As much as I'd love to include the URL with the initial bug spotting, I
> cannot as it's behind a VPN and inaccessible from the outside.
> 
> HOWEVER, I just managed to replicate the issue in codepen, here is the link:
> https://codepen.io/29pixels/pen/MWzQjXp (I also updated it in the URL field).
very cool, thanks! let me take a look.
Comment 4 Pavel Antolík 2023-07-13 07:48:17 PDT
(In reply to zalan from comment #3)
> (In reply to Pavel Antolík from comment #2)
> > Hi Zalan, what a ligtning fast response, respect!
> :)
> 
> > 
> > As much as I'd love to include the URL with the initial bug spotting, I
> > cannot as it's behind a VPN and inaccessible from the outside.
> > 
> > HOWEVER, I just managed to replicate the issue in codepen, here is the link:
> > https://codepen.io/29pixels/pen/MWzQjXp (I also updated it in the URL field).
> very cool, thanks! let me take a look.

Thanks! Hopefully we'll get to the bottom of this - fingers crossed! ^^

Btw, the codepen example felt a bit crude and out of context, so I'm also including also URL for a "full project" I just made in our production environment to further demonstrate the issue with all the bells and whistles.

Here it goes - https://bugdemo.webnode.cz/
Comment 5 zalan 2023-07-13 07:48:29 PDT
Created attachment 467033 [details]
Test reduction

This looks to be a "shrink to fit" bug where the intrinsic width computation does not take the padding (border) value into account when decoration clone is present. (e.g. we measure the content (as part of the preferred width computation) and we think it is going to fit in 100px and later when we run the actual inline layout, we notice the content is 110px wide (extra 10px comes from padding) and we need to wrap some part of it to the subsequent line.)
Comment 6 Radar WebKit Bug Importer 2023-07-13 07:49:25 PDT
<rdar://problem/112197978>
Comment 7 zalan 2023-07-13 07:58:59 PDT
(In reply to Pavel Antolík from comment #4)
> (In reply to zalan from comment #3)
> > (In reply to Pavel Antolík from comment #2)
> > > Hi Zalan, what a ligtning fast response, respect!
> > :)
> > 
> > > 
> > > As much as I'd love to include the URL with the initial bug spotting, I
> > > cannot as it's behind a VPN and inaccessible from the outside.
> > > 
> > > HOWEVER, I just managed to replicate the issue in codepen, here is the link:
> > > https://codepen.io/29pixels/pen/MWzQjXp (I also updated it in the URL field).
> > very cool, thanks! let me take a look.
> 
> Thanks! Hopefully we'll get to the bottom of this - fingers crossed! ^^
> 
> Btw, the codepen example felt a bit crude and out of context, so I'm also
> including also URL for a "full project" I just made in our production
> environment to further demonstrate the issue with all the bells and whistles.
> 
> Here it goes - https://bugdemo.webnode.cz/
Yeah, it does not look optimal. :/ will make sure the fix gets tested against it.
Comment 8 Pavel Antolík 2023-07-13 08:19:14 PDT
(In reply to zalan from comment #5)
> Created attachment 467033 [details]
> Test reduction
> 
> This looks to be a "shrink to fit" bug where the intrinsic width computation
> does not take the padding (border) value into account when decoration clone
> is present. (e.g. we measure the content (as part of the preferred width
> computation) and we think it is going to fit in 100px and later when we run
> the actual inline layout, we notice the content is 110px wide (extra 10px
> comes from padding) and we need to wrap some part of it to the subsequent
> line.)

Thanks for the heads-up - and for looking into it so quickly! I'll sleep way better now, knowing it's been officially confirmed as a browser bug. I hope fixing it won't be too much of a slog.
Comment 9 zalan 2023-07-13 11:31:13 PDT
Created attachment 467035 [details]
[fast-cq]Patch
Comment 10 zalan 2023-07-13 11:33:03 PDT
Created attachment 467036 [details]
Screenshot with patch applied
Comment 11 Pavel Antolík 2023-07-13 12:24:18 PDT
(In reply to zalan from comment #10)
> Created attachment 467036 [details]
> Screenshot with patch applied

Looking spectacular! Tbh, this is my first bugreport I filed here and just WOW. I really didn't expect what happened today :) Big ups to you Alan! Can't wait for this fix to go live.
Comment 12 Pavel Antolík 2023-07-13 12:53:49 PDT
(In reply to zalan from comment #10)
> Created attachment 467036 [details]
> Screenshot with patch applied

Just one thing I awkwardly realized way too late - the desktop-sized screenshot of a fixed state I was praising in my last comment isn't really the most telling given the fact that the bug occurs on mobile devices .)
Comment 13 zalan 2023-07-13 13:01:14 PDT
(In reply to Pavel Antolík from comment #12)
> (In reply to zalan from comment #10)
> > Created attachment 467036 [details]
> > Screenshot with patch applied
> 
> Just one thing I awkwardly realized way too late - the desktop-sized
> screenshot of a fixed state I was praising in my last comment isn't really
> the most telling given the fact that the bug occurs on mobile devices .)
It's shrink-to-fit content so I wouldn't expect anything different there, but good point. will make sure it passes on iOS.
Comment 14 zalan 2023-07-13 16:19:59 PDT
Created attachment 467037 [details]
(iOS screenshot)
Comment 15 EWS 2023-07-13 17:08:35 PDT
Committed 266051@main (e05c6e3339f4): <https://commits.webkit.org/266051@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 467035 [details].
Comment 16 Pavel Antolík 2023-07-14 04:09:42 PDT
(In reply to zalan from comment #14)
> Created attachment 467037 [details]
> (iOS screenshot)

Absolutely beautiful, thank you! One last question just out of curiosity if I may - how / when do Safari users recieve this patch? Is it in form of an automatic update, or something different?
Comment 17 zalan 2023-07-14 09:25:22 PDT
(In reply to Pavel Antolík from comment #16)
> (In reply to zalan from comment #14)
> > Created attachment 467037 [details]
> > (iOS screenshot)
> 
> Absolutely beautiful, thank you! One last question just out of curiosity if
> I may - how / when do Safari users recieve this patch? Is it in form of an
> automatic update, or something different?
Unfortunately I can't comment on future releases (and even if I could, I am not sure if I actually know the correct answer to your question)