feat: optimize re-renders for builder-component #4172
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
updateStatecalls whenever we call delete key on therootStateLoom
https://www.loom.com/share/4d19d3dacd14468aaa8f7e4a575fbe01
Note
Introduce
onChange.suspend/resumeand use them to batchrootStateresets inBuilderComponent, reducing unnecessary re-renders.packages/react/lib/on-change.js):SUSPEND/RESUMEsymbols andisSuspendedflag.onChange.suspend(proxy)andonChange.resume(proxy)APIs.ignoreChangenow skips notifications while suspended; handler exposes suspend/resume at root.packages/react/src/components/builder-component.component.tsx):builder.resetStateandbuilder.resetSymbolStatehandlers withonChange.suspend(this.rootState)/onChange.resume(this.rootState)to batch deletions/assignments.debouncedUpdateState(1s debounce) to coalesce updates.debouncedUpdateState = debounce(this.updateState, 1000).Written by Cursor Bugbot for commit 316c80d. This will update automatically on new commits. Configure here.