Skip to content

[🐞] v2 Targeting id inside style tag or useStylesScoped$ not working on client side #7393

New issue

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

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

Already on GitHub? # to your account

Closed
markovickosta opened this issue Mar 4, 2025 · 5 comments · Fixed by #7432
Closed
Assignees
Labels
COMP: runtime TYPE: bug Something isn't working VERSION: upcoming major WAITING FOR: user Further information is requested from the issue / pr opener

Comments

@markovickosta
Copy link

Which component is affected?

Qwik Runtime

Describe the bug

On user navigation style is not loaded, page needs to be refreshed for style to show.
Expected: style is shown on user interaction without needing the page reload.

const id = useId();
return (
  <style dangerouslySetInnerHTML={`#${id} { background: red; }`} />
  <div id={id}>Test</div>
)

Reproduction

markovickosta/qwik-2-test#5

Steps to reproduce

Repro:

  • Checkout branch km/dangerous-style-bug
  • npm i
  • Navigrate to any test route
  • Style is not working until page is refreshed

System Info

System:
  OS: macOS 15.3.1
  CPU: (10) arm64 Apple M4
  Memory: 255.33 MB / 16.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 22.14.0 - /usr/local/bin/node
  npm: 11.1.0 - /usr/local/bin/npm
Browsers:
  Chrome: 133.0.6943.142
  Safari: 18.3
npmPackages:
  typescript: 5.4.5 => 5.4.5 
  vite: 5.2.1 => 5.2.1

Additional Information

No response

@markovickosta markovickosta added STATUS-1: needs triage New issue which needs to be triaged TYPE: bug Something isn't working labels Mar 4, 2025
@Varixo Varixo added COMP: runtime VERSION: upcoming major and removed STATUS-1: needs triage New issue which needs to be triaged labels Mar 7, 2025
@Varixo Varixo self-assigned this Mar 8, 2025
@Varixo
Copy link
Member

Varixo commented Mar 11, 2025

The problem here is that generated id on client side is not valid CSS id selector.
https://developer.mozilla.org/en-US/docs/Web/CSS/ID_selectors#valid_id_selectors
If it starts from - it should be escaped first.
Can you use

`[id='${id}'] { ...} `

instead?

@Varixo Varixo added the WAITING FOR: user Further information is requested from the issue / pr opener label Mar 11, 2025
@markovickosta
Copy link
Author

@Varixo How can useId() start with - when it generates an uuid?

@Varixo
Copy link
Member

Varixo commented Mar 15, 2025

@Varixo How can useId() start with - when it generates an uuid?

It is not uuid :D i think we can change it to not start from -, but we can not guarantee that it will not start from a number (and this is probably also not a correct selector)

Is it different from v1?

@wmertens
Copy link
Member

@Varixo if it starts with a number we can add _ in front, no?

@Varixo
Copy link
Member

Varixo commented Mar 16, 2025

@Varixo if it starts with a number we can add _ in front, no?

right, we can :D I will do that

@Varixo Varixo linked a pull request Mar 16, 2025 that will close this issue
@Varixo Varixo closed this as completed Mar 18, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
COMP: runtime TYPE: bug Something isn't working VERSION: upcoming major WAITING FOR: user Further information is requested from the issue / pr opener
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants