Repository navigation
Conversation
|
@bdumitrua 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. |
7 of 9 tasks
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
This branch contains the commit from #242 plus one more (
perf: keep handlers stable and give each square its own style). There are two ways to merge:mainafter perf: split board context and memoize squares #242 lands. Feel free to rebase it yourself (edits from maintainers are on), or tell me and I'll do it;After #242 , two common cases still re-render the whole board:
squareStyles, for example a highlight moving to another square.This PR fixes both. The public API does not change.
How it works
All in
ChessboardProvider.tsxunless noted.onSquareClick,onPieceClick,onMouseOverSquareand the other handlers that squares call are wrapped withuseLatestHandler: a function that keeps the same identity and calls the latest handler from a ref. An inlineonSquareClick: () => ...therefore no longer changes the settings context on each render.onX?.().onPieceDrop,onPieceDrag,onPieceDragCancel,onArrowsChange) are read fromoptionsRefat call time.canDragPiecethrough a small store.DraggableandPiecesubscribes withuseSyncExternalStore(useCanDragPiece). A piece re-renders only if its own true/false result changes.useChessboardContext()still returnscanDragPiecefrom its own small context.squareStylesper square (Board.tsx,Square.tsx).squareStylesmoves out of the settings context into its own context, which onlyBoardreads.BoardpassessquareStyles[squareId]to each square as a prop, somemore-renders only the squares whose style object changed.Type of change
How Has This Been Tested?
pnpm test:staticandpnpm buildpass.Median work per update on an 8×8 board, #242 → this PR, in ms:
The gain grows with the number of squares. On a 16×16 board, stock 5.12.4 → both PRs:
With 6× throttling on 16×16, stock no longer fits a 60 fps frame during the replay (median frame 38.4 ms); with both PRs it does (17.7 ms). Dragging is dominated by dnd-kit and stays about the same.
Checklist: