Repository navigation
fix: find the animating square by id so custom board ids cannot crash - #241
Open
ryan-opatka wants to merge 1 commit into
Open
ryan-opatka wants to merge 1 commit into
ryan-opatka wants to merge 1 commit into
Conversation
The piece animation looked up its source square with
document.querySelector(`#${id}-square-...`). Ids that are not valid CSS
selectors (e.g. "1-board", "board:1", or React's useId() output like
":r0:") made querySelector throw a SyntaxError on the first animated move,
unmounting the app. Ids containing "." silently skipped the animation.
Use document.getElementById, as utils.ts already does for the same
`${id}-square-${squareId}` element.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@ryan-opatka is attempting to deploy a commit to the Ryan Gregory's projects Team on Vercel. A member of the Team first needs to authorize it. |
Author
|
Ran the project's checks locally on this branch:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Piecelooks up the source square for its move animation withThe board
idgoes into a CSS selector unescaped, so any id that isn't a valid CSS identifier breaks the first animated move:1-board,board:1, or React'suseId()output (e.g.:r0:):querySelectorthrowsSyntaxError: ... is not a valid selector. The error is thrown inside an effect, so React unmounts the tree.a.b: the selector parses as ida+ classb-square-e2, matches nothing, and the animation is silently skipped.This PR uses
document.getElementById(${id}-square-${sourceSquare}), the same lookuputils.tsalready uses for the same element (the idSquaresets on line 98). For ids that are already valid selectors, behavior is unchanged.Type of change
How Has This Been Tested?
A small Vite page using the published
react-chessboard@5.12.4(React 19.2), run in headless Chrome. For each id it renders the start position, then e4, and records uncaught errors and whether atranslate(...)animation style appears.chessboard1-boardboard:1:r0:a.bChecklist
🤖 Generated with Claude Code