Skip to content

Escape React.useId to avoid jsdom SyntaxError#1636

Open
gaborbernat wants to merge 1 commit intodownshift-js:masterfrom
gaborbernat:syntaxerror
Open

Escape React.useId to avoid jsdom SyntaxError#1636
gaborbernat wants to merge 1 commit intodownshift-js:masterfrom
gaborbernat:syntaxerror

Conversation

@gaborbernat
Copy link

@gaborbernat gaborbernat commented Feb 4, 2025

Per https://stackoverflow.com/questions/73894096/react-useid-creates-invalid-selector the : can cause SyntaxError due to React returning : charachter. This escape fixes that. Without this I am getting the following crash from nwsapi via jsdom.

SyntaxError: unknown pseudo-class selector ':r0:-menu.Menustyles__MenuPopper-sc-19x7i94-1 *'
    at emit (/frontend/node_modules/jsdom/node_modules/nwsapi/src/nwsapi.js:651:17)
    at compileSelector (/frontend/node_modules/jsdom/node_modules/nwsapi/src/nwsapi.js:1418:17)
    at compile (/frontend/node_modules/jsdom/node_modules/nwsapi/src/nwsapi.js:838:16)
    at collect (/frontend/node_modules/jsdom/node_modules/nwsapi/src/nwsapi.js:1693:22)
    at _querySelectorAll (/frontend/node_modules/jsdom/node_modules/nwsapi/src/nwsapi.js:1651:36)
    at Object._querySelector [as first] (/frontend/node_modules/jsdom/node_modules/nwsapi/src/nwsapi.js:1555:14)
    at HTMLUListElementImpl.querySelector (/frontend/node_modules/jsdom/lib/jsdom/living/nodes/ParentNode-impl.js:69:44)
    at HTMLUListElement.querySelector (/frontend/node_modules/jsdom/lib/jsdom/living/generated/Element.js:1094:58)
    at Array.Resolver (eval at compile (/frontend/node_modules/jsdom/node_modules/nwsapi/src/nwsapi.js:853:17), <anonymous>:3:98)
    at match_assert (/frontend/node_modules/jsdom/node_modules/nwsapi/src/nwsapi.js:1482:13)

Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
@gaborbernat gaborbernat changed the title Escape useID to avoid jsdom SyntaxError Escape React.useId to avoid jsdom SyntaxError Feb 4, 2025
@gaborbernat
Copy link
Author

@silviuaavram can we get this merged pelase?

@gaborbernat
Copy link
Author

@silviuaavram ping

@silviuaavram
Copy link
Collaborator

Hey @gaborbernat will take a look as I also need to address this #1674. Thanks!

@silviuaavram
Copy link
Collaborator

@gaborbernat since the error is thrown by document.querySelector(#${myId}); shouldn't you be able to fix it on your end? That's what the link actually suggests to do.

@gaborbernat
Copy link
Author

@gaborbernat since the error is thrown by document.querySelector(#${myId}); shouldn't you be able to fix it on your end? That's what the link actually suggests to do.

I think doing the escape is more robust, the issue is in a library from this library upstream that I don't control. Doing it here doesn't feel that painful.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants