Skip to content

feat: reuse resources and blocks across page loads#196

Open
shariquerik wants to merge 4 commits into
frappe:developfrom
shariquerik:feat/api-resource-cache-across-page-loads
Open

feat: reuse resources and blocks across page loads#196
shariquerik wants to merge 4 commits into
frappe:developfrom
shariquerik:feat/api-resource-cache-across-page-loads

Conversation

@shariquerik

@shariquerik shariquerik commented Jul 16, 2026

Copy link
Copy Markdown
Member

Summary

Navigating between Studio pages was always a cold load: every resource refetched and the whole block tree was reinstantiated. Three related changes:

  • Cache API resource data across page loads. Adds a "Cache data across page loads" checkbox for API Resources, so fetched data is reused instead of refetched. The cache key is derived from resource name, url, method, and resolved params, since createResource returns a cache hit before url/params/transform are applied — a name-only key would serve one page's data to another.
  • Don't clear resources while new ones resolve. setPageResources reset resources to {} before awaiting the resource promises, leaving components rendered against an empty map for the duration of the fetch. With caching on, that turned an instant cache hit into a flash of empty state. The map is now built locally and swapped in atomically.
  • Keep the block tree mounted on same-page navigation. The route watcher rebuilt rootBlock on every path change, so navigating between routes served by the same page (a list and its detail route, a view switch) destroyed component state. It now tracks the last rendered path: same-page navigation still refreshes resources and the page script, since route params may have changed, but leaves the existing blocks in place.

Test plan

  • Add an API Resource to a Studio page, enable "Cache data across page loads", confirm data persists across navigation without refetching
  • Confirm resources without caching enabled still fetch fresh data as before
  • Confirm checkbox only shows for API Resource type
  • Navigate between two routes served by the same page and confirm the blocks stay mounted (component state survives) while route-param-dependent resources re-resolve
  • Navigate to a different page and confirm the block tree is rebuilt as before

@greptile-apps

greptile-apps Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe to merge; all three changes are narrowly scoped and the logic is correct.

The cache key includes url, method, and serialized params so cross-page data bleed is not possible. The atomic resource swap and same-page block reuse are straightforward and well-guarded.

studio/studio/doctype/studio_page_resource/studio_page_resource.json — cache field lacks a depends_on guard.

Reviews (5): Last reviewed commit: "fix: keep the block tree mounted on same..." | Re-trigger Greptile

Comment thread frontend/src/stores/codeStore.ts Outdated
@shariquerik
shariquerik force-pushed the feat/api-resource-cache-across-page-loads branch from ccd5260 to 0644194 Compare July 16, 2026 11:58
@shariquerik shariquerik changed the title feat: cache API resource data across page loads feat: reuse resources and blocks across page loads Jul 20, 2026
@shariquerik
shariquerik force-pushed the feat/api-resource-cache-across-page-loads branch 3 times, most recently from 2b372cf to 83aa17e Compare July 20, 2026 06:37
Adds a "Cache data across page loads" option for API Resources, so
repeat visits to a page can reuse previously fetched data instead of
refetching, keyed on the resource's url, method, and params.
Fixes no-case-declarations lint violation in getResource by wrapping
the Document List and API Resource case bodies in blocks.
setPageResources reset resources to {} before awaiting the resource
promises, so components rendered against an empty map for the duration
of the fetch. With caching enabled that turned an instant cache hit into
a flash of empty state. Build the map locally and swap it in once.
The route watcher rebuilt rootBlock from page.blocks on every path
change, so navigating between routes served by the same Studio page
(e.g. a list and its detail route, or a view switch) reinstantiated the
whole tree and destroyed component state.

Track the last rendered path: a same-page navigation still refreshes
resources and the page script, since route params may have changed, but
leaves the existing blocks in place. Path resolution moves into
resolvePagePath() and the no-path case returns early.
@shariquerik
shariquerik force-pushed the feat/api-resource-cache-across-page-loads branch from 83aa17e to 0435b9c Compare July 20, 2026 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant