Closed Bug 1731010 Opened 3 years ago Closed 2 years ago

Github shows tab characters of mismatching widths, due to specifying font on inline-level vs. block-level ancestor

Categories

(Web Compatibility :: Site Reports, defect)

defect

Tracking

(firefox104 affected)

RESOLVED WORKSFORME
Tracking Status
firefox104 --- affected

People

(Reporter: dholbert, Unassigned)

References

()

Details

(Keywords: webcompat:site-wait)

Attachments

(3 files)

Attached file testcase 1

STR:

  1. Load attached testcase.

EXPECTED RESULTS:
Consistent indentation.

ACTUAL RESULTS:
Indentation is much smaller on first line.

NOTE:
It seems we are rendering the tab characters using the metrics from the div wrapper, rather than from the span (which is the tab characters' direct container).

This is responsible for a webcompat issue that affects the diff viewer on GitHub. In their diff viewer, the "main diff" sections (red/green/white backgrounds) has tabs rendered in a smaller font, whereas the "manually-expanded contextual code" sections (gray background) has tabs rendered in the correct larger font. This creates indentation mismatch as shown here:
https://twitter.com/Akien/status/1438219820697329671

One affected sample-page:
https://github.com/godotengine/godot/commit/5179124fd1f33c625181ea7cbd4eb109dfb71eb5
STR for that page: click the blue up-arrow to expand more contextual code at the top of the diff (above "1551"). Look at the expanded code with the gray background vs. the code with the white/green/red background, and notice that the indentation differs abruptly between the two sections.

Chrome 95 and Safari 14.1 both give EXPECTED RESULTS.

Attachment #9241500 - Attachment description: screenshot in Nightly 2021-09-15 → screenshot of issue on Github (differing indentation from different rendered tab widths) in Nightly 2021-09-15
Keywords: regression
Regressed by: 1308113

According to the spec for tab-size,

This property determines the tab size used to render preserved tab characters (U+0009). A <number> represents the measure as a multiple of the advance width of the space character (U+0020) of the nearest block container ancestor of the preserved tab, including its associated letter-spacing and word-spacing.

the tab size is based on the advance width of the block container ancestor's space character; it is not affected by font changes on inline elements. So I think Firefox is following the spec here, and the other browsers are incorrect.

I'm surprised there doesn't seem to be a WPT testcase that highlights this; I'll try creating one.

Specifically, in https://github.com/w3c/csswg-drafts/issues/5489 the CSSWG explicitly said this:

RESOLVED: Change the spec to say tab size applies to inlines but when that happens the number values apply to advance width from block container

(Previously, the spec said that tab-size only applied to blocks, not inlines; there's more discussion in the issue/IRC log.)

See Also: → 1731045

so, cleared the regression flag.

Thanks, everyone! Sounds like there's no gecko bug here after all.

I'll update the bug title to track the GitHub rendering issue here (their dependence on the WebKit/Blink behavior), and I'll reclassify this as a WebCompat bug rather than a Gecko bug.

Severity: S3 → --
Component: Layout: Text and Fonts → Desktop
Product: Core → Web Compatibility
Summary: Firefox renders tab characters at the wrong width, inside of inline-level elements with a specified font → Github shows tab characters of mismatching widths, due to specifying font on inline-level vs. block-level ancestor
Version: unspecified → Trunk

So the core issue at GitHub here is:
(1) They specify the font using the blob-code-inner class:

.blob-code-inner {
    overflow: visible;
    font-family: ui-monospace,SFMono-Regular,SF Mono,Menlo,Consolas,Liberation Mono,monospace;
    font-size: 12px;
    color: var(--color-fg-default);
    word-wrap: normal;
    white-space: pre;
}

(2) For the manually-expanded contextual lines of code (gray background), they apply that class on the block container, which is the td element:

<td class="blob-code blob-code-inner blob-code-marker" data-code-marker=" ">

(3) BUT, for the main diff section (white/green/red background), they apply that class on a span instead (and they don't specify any particular font on the block container, i.e. the td):

<td class="blob-code blob-code-addition">
  [...]
   <span class="blob-code-inner blob-code-marker" data-code-marker="+">

So for reasons discussed in comment 4 here, that means that tab characters render with inconsistent width between those two sections.

The fix here would be for them to address (3) by specifying the font on the diff-section's td element instead of (or as well as) on the span. If I make that change in devtools (just adding font-family and font-size decls on the td element), then that fixes the issue on my end.

I contacted GitHub.
Thanks Daniel.

Thanks, Karl! I've updated the URL field to include a sample affected page (see end of comment 0 for STR with that sample page, and attachment 9241500 [details] for a screenshot).

I've checked the provided TestCase, and I can still reproduce the issue.
https://prnt.sc/NQUfAleyJEy_

It still occurs in https://github.com/godotengine/godot/commit/5179124fd1f33c625181ea7cbd4eb109dfb71eb5
https://prnt.sc/fvdIYF3nVoKQ

Tested with:
Browser / Version: Firefox Nightly 104.0a1 (2022-06-29)
Operating System: Windows 10 Pro

Yeah, this is still not a Firefox bug, it's a site error on github. As described above, we're following the spec, whereas Blink and WebKit behave incorrectly (and their broken behavior happens to mask github's bad styling).

Relevant WPT test is https://wpt.fyi/results/css/css-text/tab-size/tab-size-block-ancestor.html.

I was not able to reproduce the github issue on the latest Nightly. Daniel, can you take a look and confirm, please?

Tested on:
Operating system: Windows 10
Browser/Version: Firefox Nightly 111.0a1 (2023-01-25) / Chrome 109.0.5414.75

Flags: needinfo?(dholbert)

Yup, I can't reproduce either. It looks like GitHub must've fixed their bug. Hooray!

Status: NEW → RESOLVED
Closed: 2 years ago
Flags: needinfo?(dholbert)
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: