theme-scripts icon indicating copy to clipboard operation
theme-scripts copied to clipboard

Link hash code is not safe and generates exception

Open niedfelj opened this issue 6 years ago • 1 comments

The code referenced here generates an error and is not a good implementation. For example, we have some SPA code that uses hash links to trigger pages/overlays. We have for example a link like this:

<a href="#/country-selector" class="country-selector__select-link"> Shipping to <span class="country-selector__selected-country js-country-selector-selected-country">United States</span>. <span class="country-selector__edit">EDIT</span> </a>

That href is a valid hash/href, but if you feed that to your code, it throws a DOMException

document.querySelector('#/country-selector')

https://github.com/Shopify/theme-scripts/blob/db93486d37ed151c7661634d10d55069c0b80d61/packages/theme-a11y/theme-a11y.js#L91

niedfelj avatar May 13 '19 17:05 niedfelj

@niedfelj, please open a PR with a proposed change.

t-kelly avatar May 13 '19 19:05 t-kelly