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 ID generation to ensure it produces valid CSS identifiers #3139

Merged
merged 1 commit into from
Mar 1, 2024
Merged

Fix ID generation to ensure it produces valid CSS identifiers #3139

merged 1 commit into from
Mar 1, 2024

Commits on Feb 14, 2024

  1. Fix ID generation to ensure it produces valid CSS identifiers

    * Move the logic of generating the ID into its own utility
      function.
    
    * Ensure the utility function generates IDs that are valid
      CSS identifiers.
    
      `shortid.generate()` by itself will generates IDs that
      are not always valid¹ CSS identifiers (e.g. will start
      with a digit). So, when other parts of the codebase will
      use those IDs as a selector, a `SyntaxError`² will be thrown
      (i.e. `'#...' is not a valid selector`).
    
      The `slds-` prefix is used so to keep things simple.
      `shortid.characters()` requires "a string of all 64 unique
      characters"³, which means that in order to generate valid
      CSS identifiers a-z, A-Z, and some "ISO 10646 characters
      U+00A0 and higher"¹ will need to be included.
    
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    
    ¹ From https://www.w3.org/TR/CSS21/syndata.html#value-def-identifier
    
     " In CSS, identifiers (including element names, classes, and IDs
       in selectors) can contain only the characters [a-zA-Z0-9] and
       ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and
       the underscore (_); they cannot start with a digit, two hyphens,
       or a hyphen followed by a digit. "
    
    ² https://dom.spec.whatwg.org/#selectors
    
    ³ https://github.com/dylang/shortid/blob/937ce2c8dd7001baec1785cb8dce6e6fe1bcf61f/README.md#shortidcharactersstring
    alrra committed Feb 14, 2024
    Configuration menu
    Copy the full SHA
    7decf1e View commit details
    Browse the repository at this point in the history