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

:target selector breaks with client-side routing #6432

Closed
1 task done
qw-in opened this issue May 19, 2023 · 4 comments
Closed
1 task done

:target selector breaks with client-side routing #6432

qw-in opened this issue May 19, 2023 · 4 comments

Comments

@qw-in
Copy link

qw-in commented May 19, 2023

What version of Remix are you using?

1.16.1

Are all your remix dependencies & dev-dependencies using the same version?

  • Yes

Steps to Reproduce

https://codesandbox.io/p/sandbox/interesting-tu-u6gh0r?file=%2Fpackage.json%3A1%2C1

Try the above sandbox (probably best in fullscreen mode) with JS enabled & disabled. Note the difference


  1. Link to a specific element in a page via its id <Link to="/page#element-id" />
  2. Style that element with a target selector #element-id:target { /* my styles */ }
  3. Note that during navigation with js disabled the styles are applied as expected
  4. Note that with js enabled, the styles flash briefly or are simply not applied

Expected Behavior

I would expect the behaviour to be identical with js enabled & disabled. So, I expect :target styles to be applied

Actual Behavior

:target styles are not always applied

@qw-in
Copy link
Author

qw-in commented May 19, 2023

I'll try to write an integration test this weekend if I get a chance

@brophdawg11
Copy link
Contributor

This is unfortunately correct, and has come up before although I'm having trouble finding an issue in the Remix or React Router repos (it may have just been an internal Discord discussion though). Per the spec pushState does not update the target element so :target styles only apply on full-document requests 😕

@qw-in
Copy link
Author

qw-in commented May 22, 2023

Thanks for the thorough response @brophdawg11, that makes sense. Hopefully the behaviour will change in the future - maybe with the navigation api. I'll have a look if I get a chance.

@brophdawg11
Copy link
Contributor

I hope so too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants