Skip to content

Fix list styling issue#3026

Merged
delucis merged 4 commits into
withastro:mainfrom
HiDeoo:hd-fix-list-last-child-script-styles
Apr 7, 2025
Merged

Fix list styling issue#3026
delucis merged 4 commits into
withastro:mainfrom
HiDeoo:hd-fix-list-last-child-script-styles

Conversation

@HiDeoo

@HiDeoo HiDeoo commented Mar 27, 2025

Copy link
Copy Markdown
Member

Description

Initially reported in Discord by Chris and Sarah, this PR fixes a list styling issue that can happen when the last child element of a list item is a script tag.

This can naturally happen in Starlight, e.g. in a list of steps where the last element of a step is the first occurence of a set of tabs in the page. The issue is visible in the Starlight documentation of the <Steps> component:

Before After
URL https://starlight.astro.build/components/steps/ https://deploy-preview-3026--astro-starlight.netlify.app/components/steps/
Preview SCR-20250327-kkgd SCR-20250327-kkkr

We cannot really target the built-in tabs component to fix this issue, as we could have more components that could lead to the same issue in the future, or the user could have their own component that triggers the issue.

We also cannot fix this issue if only the last child element of a list item is a script tag, as even if rare, the last n child elements could be script tags too.

This leads to quite the complex selector to try to handle all cases, I tried to comment it as much as possible to make it more understandable.

@changeset-bot

changeset-bot Bot commented Mar 27, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e6a0b3e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@astrojs/starlight Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions Bot added the 🌟 core Changes to Starlight’s main package label Mar 27, 2025
@netlify

netlify Bot commented Mar 27, 2025

Copy link
Copy Markdown

Deploy Preview for astro-starlight ready!

Name Link
🔨 Latest commit e6a0b3e
🔍 Latest deploy log https://app.netlify.com/sites/astro-starlight/deploys/67f3e269140b32000828c404
😎 Deploy Preview https://deploy-preview-3026--astro-starlight.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 100 (no change from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@delucis delucis requested a review from Copilot March 27, 2025 10:50

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a list styling issue that occurs when the last element of a list item is a <script> tag, which can interfere with proper styling in components like .

  • Added a changeset to update the '@astrojs/starlight' package with a patch
  • Documented the fix for better traceability and reference in future debugging
Files not reviewed (1)
  • packages/starlight/style/markdown.css: Language not supported

@delucis delucis left a comment

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.

Thanks for the fix. I think the selector is good and the comment is helpful 👍

Left a comment for us to think about.

* need to style the last non-script element (`:not(script)`) that doesn't have a subsequent
* sibling that is not a script (`:not(:has(~ :not(script)))`).
*/
:not(script):has(~ script:last-child):not(:has(~ :not(script)))

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.

Noting that :has() is technically not covered by our documented browser support matrix (not supported in Chrome/Edge 88–104 and Firefox 98–120). So far we only used it once in a non-critical hover style on <details>.

I think it’s OK for us to start to drop those older browsers (they’re releases from 2023 and earlier with <0.5% usage) but we should probably update our documented list (and maybe mention that in the changeset?)

It would also be possible here to keep the existing selector with the :has() variant added in addition as a progressive enhancement I guess? But not sure if it’s worth it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good call, it's already bumped in #2322 which would fix it for Firefox but not Chrome. I'll update the PR so that it's only 1 bump for both PRs 👍

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated our browserslist query to support both this PR and #2322 (which I'll need to update to remove the equivalent change). It's a 0.8% coverage decrease. I've also bumped the changeset to a minor version and also described the change in it (open to suggestion regarding the wording).

@trueberryless

Copy link
Copy Markdown
Contributor

Pull Request Overview

This PR fixes a list styling issue that occurs when the last element of a list item is a <script> tag, which can interfere with proper styling in components like .

  • Added a changeset to update the '@astrojs/starlight' package with a patch
  • Documented the fix for better traceability and reference in future debugging
Files not reviewed (1)
  • packages/starlight/style/markdown.css: Language not supported

What is THAT? Please don't tell me this is now enabled by default on GitHub... 🙏

@HiDeoo

HiDeoo commented Mar 27, 2025

Copy link
Copy Markdown
Member Author

What is THAT? Please don't tell me this is now enabled by default on GitHub... 🙏

No, we just were curious, but it's manual https://docs.github.com/en/copilot/using-github-copilot/code-review/using-copilot-code-review

@delucis

delucis commented Mar 27, 2025

Copy link
Copy Markdown
Member

Yeah, we were curious, but it doesn’t even understand CSS so pretty useless 😅

@delucis delucis left a comment

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.

Looks good I think. Left a small suggestion on the changeset for your consideration.

Comment thread .changeset/calm-cobras-breathe.md Outdated
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
@delucis delucis added the 🌟 minor Change that triggers a minor release label Apr 1, 2025
@delucis delucis added this to the v0.33 milestone Apr 5, 2025
@delucis delucis added the ✅ approved Pull requests that have been approved and are ready to merge when next cutting a release label Apr 5, 2025
@delucis delucis merged commit 82deb84 into withastro:main Apr 7, 2025
@astrobot-houston astrobot-houston mentioned this pull request Apr 7, 2025
Yoxnear pushed a commit to Yoxnear/starlight-custom that referenced this pull request Jul 23, 2025
Co-authored-by: Chris Swithinbank <swithinbank@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✅ approved Pull requests that have been approved and are ready to merge when next cutting a release 🌟 core Changes to Starlight’s main package 🌟 minor Change that triggers a minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants