Skip to content

Use solid color for table row border to fix Safari rendering issue#25682

Merged
gzdunek merged 5 commits intomasterfrom
gzdunek/safari-border-color
May 5, 2023
Merged

Use solid color for table row border to fix Safari rendering issue#25682
gzdunek merged 5 commits intomasterfrom
gzdunek/safari-border-color

Conversation

@gzdunek
Copy link
Copy Markdown
Contributor

@gzdunek gzdunek commented May 5, 2023

e counterpart https://github.com/gravitational/teleport.e/pull/1310

When border-collapse: collapse is set on a table element, Safari incorrectly renders row border with alpha channel.
It looks like the collapsed border was rendered twice, that is, opacity 0.07 looks like opacity 0.14 (this is more visible on dark theme). Sometimes, there is also an artifact visible after hovering the rows - some of them have correct border color, some not. Here you can see it - the first two rows have too bright border:
Screenshot 2023-05-05 at 08 06 49


This PR redo the changes I made in #25333, but in a different way. I realized that adding a border to td elements is risky, because these elements don't necessarily have the same height as tr (this caused a bug for the status cell in RequestList.tsx):
image

The updated workaround is to use a solid color for the borders.

Comment on lines 104 to 115
Copy link
Copy Markdown
Contributor Author

@gzdunek gzdunek May 5, 2023

Choose a reason for hiding this comment

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

Any opinions on hardcoding the final values here? I'm a little worried that calculating it with every render may cause some perf issues when rendering a lot of rows.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What do you mean by hardcoding them here?

I actually don't know how styled components work with these custom functions using props, are they going to compile the style only once and then extract it to a CSS file?

Copy link
Copy Markdown
Contributor Author

@gzdunek gzdunek May 5, 2023

Choose a reason for hiding this comment

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

What do you mean by hardcoding them here?

return "rgb(49,58,100)"; 🙈

But nvm, it doesn't make any sense, because:

  1. We create style for an entire table, not for each row separately.
  2. The style is probably re-complied only when the prop changes, I added console.log to getSolidRowBorderColor and it was only invoked again only when I changed the theme.

Btw, styled-components doesn't create a CSS file, but:

styled-components generates an actual stylesheet with classes, and attaches those classes to the DOM nodes of styled components via the className prop. It injects the generated stylesheet at the end of the head of the document during runtime.

@gzdunek gzdunek force-pushed the gzdunek/safari-border-color branch from cc367af to 26ac912 Compare May 5, 2023 07:26
// the value of theme.colors.spotBackground[0]
function getSolidRowBorderColor(theme) {
const alpha = decomposeColor(theme.colors.spotBackground[0]).values[3];
if (theme.name === 'dark') {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Regarding what I said on #dev-frontend about not using theme name conditionals, could you instead use the emphasize function from colorManipulator.js? I'm not sure if it achieves exactly what you want here, you might need to reimplement it reversing the logic if needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is awesome, thank you! empasize works without any changes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Usually it'd be better to add a new color to the theme but since this is just a workaround for a browser bug, I think we can get away with using emphasize.

@ravicious ravicious self-requested a review May 5, 2023 10:34
Copy link
Copy Markdown
Member

@ravicious ravicious left a comment

Choose a reason for hiding this comment

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

Some reproduction steps would be useful since comparing the colors doesn't seem to be trivial, but I trust you that the issue was indeed present.

I think the only thing I personally need is a clarification as to how it affects non-Safari browsers and if we're okay with how this change affects them.

// the value of theme.colors.spotBackground[0]
function getSolidRowBorderColor(theme) {
const alpha = decomposeColor(theme.colors.spotBackground[0]).values[3];
if (theme.name === 'dark') {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Usually it'd be better to add a new color to the theme but since this is just a workaround for a browser bug, I think we can get away with using emphasize.

// WebKit issue https://bugs.webkit.org/show_bug.cgi?id=35456.
//
// `getSolidRowBorderColor` is a workaround. The color is created by lightening or darkening the table background by
// the value of theme.colors.spotBackground[0].
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This comment explains what is being done but it doesn't explain how it fixes the problem, does it? Could we add an explanation here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added, is it more clear now?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, it is!

The final color is created by lightening or darkening the table background color by the value of theme.colors.spotBackground[0].

Did you mean the value of the alpha channel of theme.colors.spotBackground[0]?

Also, I suppose this assumes that spotBackground is (more or less) a pure white or black color with an alpha channel. Which I think is one of the core assumption of the theme anyway. It should be fine as long as we communicate that to users. (cc @roraback @rudream)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Did you mean the value of the alpha channel of theme.colors.spotBackground[0]?

Ah yes.

Also, I suppose this assumes that spotBackground is (more or less) a pure white or black color with an alpha channel. Which I think is one of the core assumption of the theme anyway. It should be fine as long as we communicate that to users.

👍

Comment thread web/packages/design/src/DataTable/StyledTable.tsx Outdated
// WebKit issue https://bugs.webkit.org/show_bug.cgi?id=35456.
//
// `getSolidRowBorderColor` is a workaround. The color is created by lightening or darkening the table background by
// the value of theme.colors.spotBackground[0].
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, does it mean that in browsers other than Safari the border colors will appear to be slightly different than what the user might expect?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, Firefox and Chrome render the same border color (visually) as before the fix.
You can try replacing

  tbody tr {
    border-bottom: 1px solid ${getSolidRowBorderColor(props.theme)};
  }

with

  tbody tr {
    border-bottom: 1px solid ${props.theme.colors.spotBackground[0]};
  }

there won't be any difference.

The only thing that has slightly changed is the visibly of borders on hover.
Previously, they were slightly visible:
Screenshot 2023-05-05 at 15 40 45

Now, they are mixed with the hover color:
Screenshot 2023-05-05 at 15 39 46

I guess that's because previously we had an alpha from border + alpha from hover and they were mixed differently than alpha from hover + solid border color.

But I don't think it is a problem, they look fine either way.

@public-teleport-github-review-bot public-teleport-github-review-bot Bot removed the request for review from ibeckermayer May 5, 2023 14:31
@gzdunek gzdunek enabled auto-merge May 5, 2023 14:32
@gzdunek gzdunek added this pull request to the merge queue May 5, 2023
Merged via the queue into master with commit 17394c2 May 5, 2023
@gzdunek gzdunek deleted the gzdunek/safari-border-color branch May 5, 2023 14:48
@public-teleport-github-review-bot
Copy link
Copy Markdown

@gzdunek See the table below for backport results.

Branch Result
branch/v13 Failed

gzdunek added a commit that referenced this pull request May 5, 2023
…25682)

* Use solid color for table row border to fix Safari rendering issue

* Use `emphasize` function

* Improve comment

* Add fallback value to alpha

* Clarify comment

(cherry picked from commit 17394c2)
gzdunek added a commit that referenced this pull request May 5, 2023
…sue (#25711)

* Use solid color for table row border to fix Safari rendering issue (#25682)

* Use solid color for table row border to fix Safari rendering issue

* Use `emphasize` function

* Improve comment

* Add fallback value to alpha

* Clarify comment

(cherry picked from commit 17394c2)

* Update Sessions snapshot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants