Skip to content

Cascade layer issues/feedbacks #3162

Open
@HiDeoo

Description

@HiDeoo

This issue is more of an umbrella for the various issues and feedback gathered regarding the style changes from Starlight 0.34.0 and the switch to cascade layers.

Technical issues

1. Missing styles

Workaround shipped in Starlight 0.34.2

History

Not technically related to the changes in 0.34.0, but seems to be more easily reproducible due to some refactoring in this release. If an integration or Starlight plugin injecting dynamic routes that also render the <StarlightPage> component, due to an head propagation issue, some styles can end up missing in development mode.

2. Custom pages layer order

For custom pages rendered using the <StarlightPage> component, due to how import order for stylesheets works in Astro, importing <AnchorHeading> or any Starlight component before <StarlightPage> breaks the expected layer order as we cannot control the order in this case like we do for Starlight pages.

  • Opened a tentative PR to fix this issue but ended up fixing the issue in dev but breaking in production
  • Need to investigate further if we can somehow reliably enforce the order in such cases
  • If not, we would need to document this behavior and suggest to import <StarlightPage> before any other Starlight component

Documentation feedback

3. Do I have to use cascade layers?

Documentation updated in #3167 and we will monitor for extra feedback to see if we need to improve the documentation further.

History

It looks like some users could be confused by the fact that we are using cascade layers in Starlight and that they may also need to use them in their own stylesheets. The "any custom unlayered CSS will override the default styles" may not be clear enough.

  • We should figure out how to emphasize that cascade layers are not mandatory for user stylesheets. Starlight use them internally, users can use them if they want to, but they are not required
4. I was expecting Starlight to override my styles, but it's no longer the case

Documentation updated in #3167 and we will monitor for extra feedback to see if we need to improve the documentation further.

History

This case is a bit more tricky as I think having authored CSS that is expected to be overridden by Starlight is a bit confusing. Altho, I guess this can happen e.g. for someone migrating to Starlight, importing all their existing custom CSS and only tweaking them enough to make them work with Starlight.

Now, with the cascade layers, any unlayered CSS will override Starlight styles, so any authored CSS will win and can lead to unexpected results.

  • Not quite sure yet how to document/provide guidance for this case
5. Tailwind customCss ordering

Documentation updated in #3170 and we will monitor for extra feedback to see if we need to improve the documentation further.

History

A few users have already run in this issue where their ./src/styles/global.css was not being the first element in the customCss array which can definitely cause unexpected behavior.

6. I'm using custom pages or Starlight at a subpath and want Tailwind on both my site/custom pages and Starlight.

When using custom pages or Starlight at a subpath and want to use Tailwind on both your main site/custom pages and Starlight, you propably want to use a default Tailwind setup for your main website and a different one for Starlight which would use the Starlight’s Tailwind compatibility package.

This has already been asked quite a bit of times, and even tho it's a bit similar to how this used to work with Tailwind v3, it may not be obvious that you want to use different CSS files.

  1. For the main website, one CSS file that will probably be imported in a layout component

    @import "tailwindcss";
  2. For Starlight, the one we document that will be referenced in Starlight customCss config option.

    @layer base, starlight, theme, components, utilities;
    
    @import '@astrojs/starlight-tailwind';
    @import 'tailwindcss/theme.css' layer(theme);
    @import 'tailwindcss/utilities.css' layer(utilities);
  • Figure out if we can hint at this in the documentation

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions