Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent list items from overflowing Markdown content #1736

Merged

Conversation

julien-deramond
Copy link
Contributor

@julien-deramond julien-deramond commented Apr 10, 2024

Description

Context

This PR is an attempt to fix an issue reported in this Discord > starlight > Text overflow issue thread.

On iPhone XR, OP could see on a 414px width screen the following (at https://0d6fe6ee.chart-docs.pages.dev/charts/dependency/kube-state-metrics/) which results in a horizontal scrollbar:

Screenshot 2024-04-10 at 19 17 46

It can also be observed, at least on macOS with Safari and Chrome.

Changes

As you can see in the deployed documentation, I've tested some long links in the regular content, but also in ordered and unordered lists. Regular content is fine, while the long links in the lists are overflowing.

The idea here is to rely on the same fixes that happened in #756 and #814 based on the use of overflow-wrap: anywhere.

Not knowing in detail the codebase of Starlight, I suppose that reducing the scope to .sl-markdown-content li is acceptable (I've added a reddish background for visual manual regression testing). Indeed, adding this rule directly in the reset.css might have some unexpected repercussions.

Here's the rendering before the fix.

Screenshot 2024-04-10 at 19 24 01

Here's the rendering after the fix (directly accessible at https://starlight-git-fork-julien-deramond-main-jd-bab67d-astrodotbuild.vercel.app/guides/authoring-content/):

Screenshot 2024-04-10 at 19 23 16

Non-regression testing

I'm sorry but I haven't tested yet some impacts that would maybe need a stricter CSS rule, and I'll be off for 1 week tomorrow.

Some use cases that could be impacted:

Copy link

changeset-bot bot commented Apr 10, 2024

🦋 Changeset detected

Latest commit: b82f34d

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 Patch

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

Copy link

vercel bot commented Apr 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
starlight ✅ Ready (Inspect) Visit Preview May 16, 2024 8:48pm

@github-actions github-actions bot added 📚 docs Documentation website changes 🌟 core Changes to Starlight’s main package labels Apr 10, 2024
Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

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

Thank you for jumping into this so quickly @julien-deramond!

I did some quick testing across the Starlight docs to investigate the potential for regressions (hard to be sure for all user content, so I’m hoping our range of content is a good enough test case).

I did find one specifically in our <Tabs> component that should never wrap and instead scroll horizontally when they overflow:

tabs for different package managers with the names overflowing onto two lines

I guess we’ll need to override the overflow-wrap: anywhere for that component. It also gives a small indication that this could have an impact on user components in theory.

It makes me wonder if our global rule setting this should be scoped to the Markdown content and use :not(:where(.not-content *)) like the other rules to make it easier for users to escape that styling if needed. This rule here:

https://github.com/withastro/starlight/blob/main/packages/starlight/style/reset.css#L35-L44

@julien-deramond
Copy link
Contributor Author

I guess we’ll need to override the overflow-wrap: anywhere for that component. It also gives a small indication that this could have an impact on user components in theory.

Yes, if it is difficult to measure the impact on Starlight side, we can be sure that it will have an impact on users' components.

It makes me wonder if our global rule setting this should be scoped to the Markdown content and use :not(:where(.not-content *)) like the other rules to make it easier for users to escape that styling if needed. This rule here:

https://github.com/withastro/starlight/blob/main/packages/starlight/style/reset.css#L35-L44

My first version was adding li to this rule, but it was a little bit "scary" not to be able to measure the impact and the potential regressions for the users, not knowing all the details of the codebase.

I'd be in favor to scope it to the Markdown content. It would seem to be the most maintainable approach for the Starlight core team, and maybe also less opinionated and/or impactful for the users and their components, yeah.

@HiDeoo
Copy link
Member

HiDeoo commented Apr 18, 2024

Thanks for the great contribution. We reviewed this PR with a lot of eyes/devices/browsers today in Astro Talking & Doc'ing session.

To do so, we had everyone browse random pages on various Starlight websites (Starlight Docs, Astro Docs, SST Ion docs and Knip Docs) where I implemented ahead of time the suggested fix from this PR.

With exactly the suggested changes from this PR, no extra issue except the one spotted by Chris regarding the <Tabs> component was found.

We tried a slight variation of the selector (.sl-markdown-content li:not(:where(.not-content *))) which prevents this issue as the tabs list wrapper uses the not-content class. Altho, as spotted during the session, this would not work in the case of the <Tabs> component nested in the <Steps> component for example.

Did not play more than that yet with the selector, but I guess it will need a bit more tweaking to handle those cases.

@astrobot-houston
Copy link
Collaborator

astrobot-houston commented May 15, 2024

Lunaria Status Overview

🌕 This pull request will trigger status changes.

Learn more

By default, every PR changing files present in the Lunaria configuration's files property will be considered and trigger status changes accordingly.

You can change this by adding one of the keywords present in the ignoreKeywords property in your Lunaria configuration file in the PR's title (ignoring all files) or by including a tracker directive in the merged commit's description.

Tracked Files

Locale File Note
en getting-started.mdx Source changed, localizations will be marked as outdated.
en guides/authoring-content.md Source changed, localizations will be marked as outdated.
en guides/customization.mdx Source changed, localizations will be marked as outdated.
Warnings reference
Icon Description
🔄️ The source for this localization has been updated since the creation of this pull request, make sure all changes in the source have been applied.

@julien-deramond
Copy link
Contributor Author

julien-deramond commented May 15, 2024

Sorry for the delay, I was off and also overwhelmed by other OSS repos.

Based on #1736 (comment) and #1736 (review), I've reset the overflow-wrap value for tab items via d5fae7d#diff-07167ef1e6f2c6cadc53adf10a29f1e6057bcfad18c10b956fbfa6626bf43f15.

This can be tested out here:

With these modifications, the PR should cover all use cases.

@julien-deramond julien-deramond marked this pull request as ready for review May 15, 2024 18:55
Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

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

Thank you for following up on this @julien-deramond! Just played around with it again and I think this is indeed the best approach.

I do wonder if our generic set-up for this in reset.css ought really also to be moved to markdown.css:

p,
h1,
h2,
h3,
h4,
h5,
h6,
code {
overflow-wrap: anywhere;
}

In a quick check, I think the only element this currently applies to which is outside of the Markdown content is the page title.

But that can happen as follow-up work to keep this PR focused on the specific fix.

@@ -65,6 +65,7 @@ const { html, panels } = processPanels(panelHtml);
border-bottom: 2px solid var(--sl-color-gray-5);
color: var(--sl-color-gray-3);
outline-offset: var(--sl-outline-offset-inside);
overflow-wrap: initial;
Copy link
Member

Choose a reason for hiding this comment

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

Agree that this makes sense given how overflow-wrap is inherited 👍

packages/starlight/style/markdown.css Outdated Show resolved Hide resolved
@julien-deramond
Copy link
Contributor Author

I do wonder if our generic set-up for this in reset.css ought really also to be moved to markdown.css:
In a quick check, I think the only element this currently applies to which is outside of the Markdown content is the page title.
But that can happen as follow-up work to keep this PR focused on the specific fix.

Yes, I can take a look in a follow-up PR to ease the review and evaluate the impacts.

Whenever this PR is accepted, feel free to ping me so that I can remove the extra testing data before merging :)

Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

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

I think everything looks good to me!

We can remove the background colour and the test content I think.

@github-actions github-actions bot removed the 📚 docs Documentation website changes label May 16, 2024
Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

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

Perfect — this looks good to me!

Would you want to write a changeset for the changelog (you can use the link in the bot comment above to add one), or would you prefer me to take care of that?

@julien-deramond
Copy link
Contributor Author

Tried to add one thanks to your doc via b82f34d.
Chose "patch" bump.
Feel free to modify it so that it's consistent with the other changesets :) I'm not that aware of your architecture and release management.

Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

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

Thanks again for the thoroughness working out the solution @julien-deramond and @HiDeoo for running it through the Talking & Doc’ing testing machine 💖

@delucis delucis added the 🌟 patch Change that triggers a patch release label May 16, 2024
@delucis delucis merged commit cfa94a3 into withastro:main May 16, 2024
11 checks passed
@astrobot-houston astrobot-houston mentioned this pull request May 16, 2024
@julien-deramond julien-deramond deleted the main-jd-fix-markdown-content-li-wrap branch May 16, 2024 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌟 core Changes to Starlight’s main package 🌟 patch Change that triggers a patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants