Repository navigation
Conversation
…vided The Editor component unconditionally subscribes with a collector that calls query.serialize() (a JSON.stringify of the entire node tree) on every store change, solely to detect whether the onNodesChange callback should fire. For consumers that never pass onNodesChange - typically read-only viewers/renderers that receive frequent runtime prop updates - this serialization is pure overhead: on a page with ~500 nodes (~450KB of serialized JSON) every incoming data update paid a full-tree stringify, which profiling showed to be the single largest JS cost and a major source of GC pressure. Only set up the subscription when the consumer explicitly provides onNodesChange. Editors that pass the callback are unaffected.
|
@hnldlsjzt is attempting to deploy a commit to the Prev Wong's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
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.
Problem
<Editor>unconditionally subscribes with a collector that callsquery.serialize()— aJSON.stringifyof the entire node tree — on every store change, solely to detect whether theonNodesChangecallback should fire:https://github.com/prevwong/craft.js/blob/master/packages/core/src/editor/Editor.tsx#L94-L103
Since
onNodesChangedefaults to a no-op, consumers that never pass it still pay this serialization cost on every state change.Real-world impact
We render read-only pages (
enabled: false) that receive frequent runtime prop updates over WebSocket (industrial monitoring dashboards running 24/7). On a page with ~500 nodes (~450 KB serialized JSON), CPU profiling showed:With this fix applied (verified via pnpm patch in production), overall busy time on a 20-second profile dropped from 11.8% to 5.5%, with the serialize cost going to zero.
Fix
Only set up the subscription when the consumer explicitly provides
onNodesChange. Consumers that pass the callback (i.e. editors) are unaffected — the subscription is created exactly as before. The guard also protects againstcontextbeing null, consistent with the other effects in the component.No API changes, no behavior changes for existing
onNodesChangeusers.