Skip to content

perf: speed up canvas loading for repeated collections#366

Merged
tristan-mouchet merged 1 commit into
developfrom
fix/dedupe-canvas-collection-requests
Jun 16, 2026
Merged

perf: speed up canvas loading for repeated collections#366
tristan-mouchet merged 1 commit into
developfrom
fix/dedupe-canvas-collection-requests

Conversation

@tristan-mouchet

Copy link
Copy Markdown
Collaborator

Summary

Loading a page in the builder canvas was slow when a collection is repeated across many component instances (common with reference collections). Each instance fired its own identical API request; on large collections these ran concurrently and saturated the event loop, making the canvas take a long time to load.

Changes

  • Add a shared in-flight/result cache in useCollectionLayerStore, keyed by the full request signature (collection + sort + limit + offset + filters)
  • Layers bound to the same collection with identical params now reuse a single request instead of each firing its own
  • Applied to both initial load (fetchLayerData) and post-edit refetch (refetchLayersForCollection)
  • Cache is cleared on invalidateLayerData (per collection) and clearAllLayerData (all) so CMS edits and page switches still refetch fresh data
  • Failed requests are dropped from the cache so retries work

Test plan

  • Open a page with a collection repeated across many instances — only one network request fires per unique collection/params
  • Edit a CMS item in that collection — canvas refetches and shows the update
  • Switch pages and back — data still loads correctly
  • Verify a collection used with different sort/limit/offset still fetches separately

Collection layer data was cached per layerId, so a collection repeated
across many component instances (common with reference collections)
fired one identical request per instance. On large collections these
ran concurrently and saturated the event loop, making the canvas slow
to load. Share one in-flight/resolved request across layers with the
same collection and params, cleared on invalidation.
@tristan-mouchet tristan-mouchet added the Improvement Improve existing feature label Jun 16, 2026
@tristan-mouchet tristan-mouchet self-assigned this Jun 16, 2026
@tristan-mouchet tristan-mouchet merged commit c31b543 into develop Jun 16, 2026
1 check was pending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Improvement Improve existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant