Skip to content

Unexpected Behavior when including URL Fragment in url-prefix #1929

@BoffinBrain

Description

@BoffinBrain

At the moment, when you're on a page with a fragment (anything after the # symbol) and you choose to Write Style For (clicking the entire URL), that fragment is included in the url-prefix. This causes a couple of issues:

  1. Stylus only activates the style when that exact fragment is present in the URL at the time the page is loaded. Clicking a hyperlink to change the fragment later doesn't include the style. While this makes sense from a technical perspective, it could be seen as undefined/buggy behavior.
  2. Since the fragment usually isn't visible when clicking Write Style For because it's cropped off the end of the line, this might cause confusion for the author later.

I've provided a simple example style below. If you go to that exact URL the style will work. If you just go to the Wiki page and click 'Setting a Hotkey' in the table of contents, the URL bar shows the fragment but Stylus doesn't activate the style.

I would suggest a quick fix by not including URL fragments when Write Style For is chosen, to avoid these issues, since the author probably doesn't want it. Whether you want Stylus to activate/deactivate styles when the fragment changes... is up to you.

System Information

  • OS: Windows 10
  • Browser: Firefox 136.0b6
  • Stylus Version: 2.3.10

Screenshots, links, CSS

/* ==UserStyle==
@name           Github Fragment Test
@namespace      github.com/openstyles/stylus
@version        1.0.0
@description    A new userstyle
@author         Me
==/UserStyle== */

@-moz-document url-prefix("https://github.com/openstyles/stylus/wiki/Colorpicker#setting-a-hotkey") {
    .AppHeader-localBar li:nth-child(1) {
        background: red;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions