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

autoShapes array does not truncate when changed in the config #184

Closed
jlambert23 opened this issue Apr 8, 2021 · 0 comments
Closed

autoShapes array does not truncate when changed in the config #184

jlambert23 opened this issue Apr 8, 2021 · 0 comments
Labels

Comments

@jlambert23
Copy link
Contributor

jlambert23 commented Apr 8, 2021

I am running into an issue where the autoShapes are not properly updating while using react-chessground. I tracked the problem to config.ts so decided to create the issue here. config.ts is what is being used as input from the props to rerender the chessboard.

From what I've found, the merge function only replaces the base's array elements with elements of the same index in the extend's array. If the extend's array is smaller, only those values will be copied over. If the extend's array is empty, then there are no changes made to the base array. In either case, it's only possible for the corresponding array in base to grow, never shrink (see TS playground demo).

It's also evident that this functionality has caused a hiccup before because there is some post-processing being performed for lastMove to handle this exact scenario.

I think this is an inherit problem with the merge algorithm, but I imagine changing it to replace arrays instead of merging them might cause some unexpected behavior. In which case, I suggest adding post-processing for autoShapes, similar to that of lastMove:

  if ('lastMove' in config && !config.lastMove) state.lastMove = undefined;
  // in case of ZH drop last move, there's a single square.
  // if the previous last move had two squares,
  // the merge algorithm will incorrectly keep the second square.
  else if (config.lastMove) state.lastMove = config.lastMove;

For reference, this has also been reported in react-chessground, however the issue seems to stem directly from the code in config.ts.

@niklasf niklasf added the bug label Apr 8, 2021
ornicar added a commit that referenced this issue Apr 14, 2021
override autodrawable in config (issue #184)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants