Skip to content

[Firefox] data attributes are broken / not targeted for styling when building the site using theme-classic #9493

@jprusik

Description

@jprusik

Have you read the Contributing Guidelines on issues?

Prerequisites

Description

tl;dr Firefox does not yet support :has (at least not by default)

On Firefox, when I'm using the (default) theme-classic theme and locally serve the build files (npm run build && npm run serve), custom data attributes selectors are not styled as described in the Docusaurus docs. When I serve the site via the development server (npm run start), the custom data attributes selectors are styled properly. (I tested this in a fresh/new project)

Also affects the dark/light mode toggle on the live docusaurus site:
#9493 (comment)

After looking around, I tracked the issue down to the built CSS:

custom.css working generated CSS (dev server) not working generated CSS (built)
Screenshot 2023-11-01 at 12 51 30 PM Screenshot 2023-11-01 at 12 51 56 PM Screenshot 2023-11-01 at 12 47 57 PM

After working with the built/optimized CSS, I was able to determine the rule was preventing the rest of the selectors in the combined rules from being evaluated:

Screenshot 2023-11-01 at 12 59 55 PM

This belongs to the Navbar Search component and it appears the problematic rule was introduced in this PR:
https://github.com/facebook/docusaurus/pull/9385/files#diff-b05b40971ea5fe3fbfdb4aee1fa6f1f4989d591465acbf2d45c84200223c36a8R12-R14

As a workaround, I can eject the component (docusaurus swizzle @docusaurus/theme-classic Navbar/Search --eject) and remove the rule (in src/theme/Navbar/Search/styles.module.css) to restore the expected data attribute styling functionality, but it would be nice if this was not necessary.

Note: I did confirm the data-attributes were correctly being pulled from the query string and added to the document html:

Screenshot 2023-11-01 at 12 49 44 PM

Reproducible demo

No response

Steps to reproduce

  1. create a new instance of docusaurus (e.g. npx create-docusaurus@latest del-test classic --typescript)
  2. add custom styling using custom data attribute selectors as described in the Docusaurus docs

e.g.

.hidden,
[data-bare='true'] .navbar {display:none;}
[data-bare='true'] .footer {display:none;}
[data-bare='true'] .theme-doc-sidebar-container {display:none;}
[data-bare='true'] .pagination-nav {display:none;}
[data-bare='true'] .theme-doc-markdown > header {display:none;}
[data-hide-sidebar='true'] .theme-doc-sidebar-container {display:none;}
[data-hide-pagination='true'] .pagination-nav {
  display: none;
}
  1. build and serve the site (npm run build && npm run serve)
  2. add the data-attribute(s) to the query string - the styling rules will not be used

Expected behavior

custom data attributes should be styled as described in the Docusaurus docs when serving the built files and using the theme-classic theme

Actual behavior

custom data attributes are not styled as described in the Docusaurus docs when serving the built files and using the theme-classic theme

Your environment

  • Docusaurus version used: v3.0.0
  • Environment name and version (e.g. Chrome 89, Node.js 16.4): Firefox, Node v18.18.2
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS): Mac OS 14.0

Self-service

  • I'd be willing to fix this bug myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn error in the Docusaurus core causing instability or issues with its executiondomain: themeRelated to the default theme components

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions