-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
Better error message when the scrollBehavior selector is invalid #3008
Comments
After further research, I'm realizing that trying to be smart and detect valid id selectors is a bad idea because there are cases where it won't be possible. Adding support for hashes starting with a number was a mistake and has been removed in v4. So instead I think we should do the following
|
Hi @posva thanks for coming back. Couple of notes ... It's been a while, but I think the gist/context of the original PR was that Given that the hash is meant to map to an I like the new error message, it will definitely help debug. If it's still the case, can I suggest that it's also noted in the documentation that |
Vue Router doesn't replicate the hash scrolling from the browser, we use Note the fragment of the url has multiple use cases, anchoring to an id of the page is the most common one but only one of them. I think it would be better to deprecate |
Nice updates! These all make a lot more sense I think - more clarity, less edge-cases 😁 Sorry for the confusion around the hash scrolling, I had quickly looked through my own code / fix to see where the PR had originated from and that seemed to be the case. Note there is reference to the scroll-to-hash behaviour in the docs, specifically it mentions passing |
Glad to hear it makes more sense! The docs should indeed note that to be clear it would be Another possibility would be to always use an I will write an RFC for this, it's worth one |
posted vuejs/rfcs#176 |
What problem does this feature solve?
Currently if you pass a hash id with unescaped CSS special characters
/[!"#$%&'()*+,\-./:;<=>?@[\\]^{|}~]/
to a scrollBehavior selector, execution will fail:Because of this url-styled hashes (e.g.
"#one/two"
or"#main/secondary"
), both valid ids in HTML5, cannot be passed directly from theto.hash
orfrom.hash
parameters.This is because behind the scenes
document.querySelector
, which relies on CSS character compliance, is used in all but a very small number of circumstances (i.e./^#\d/
). This feature proposes broadening the use case fordocument.getElementById
to all selectors that have the appearance of an id, specifically ungrouped selectors starting with a hash (i.e./^#[^, ]+$/
)What does the proposed API look like?
API doesn't change, except the following would work:
The text was updated successfully, but these errors were encountered: