Skip to content

Fix: access query exposed values directly in RunJS context#16357

Merged
johnsoncherian merged 4 commits into
mainfrom
fix/access-query-data
May 11, 2026
Merged

Fix: access query exposed values directly in RunJS context#16357
johnsoncherian merged 4 commits into
mainfrom
fix/access-query-data

Conversation

@kavinvenkatachalam
Copy link
Copy Markdown
Collaborator

📝 What this does

Fixes a bug where queries.queryName.data (and other properties like error, request, response, metadata) returned stale snapshot values when accessed after await queries.queryName.run() inside a RunJS query. Properties now read live from the store, so the result of the completed run is always reflected.

🔀 Changes

  • Replaced deep-cloned snapshot of query state with live Object.defineProperty getters for all state fields (data, rawData, isLoading, error, request, response, metadata, responseHeaders)
  • Pre-resolves query ID at construction time so each getter does a cheap O(1) store lookup instead of a full getResolvedState traversal
  • Initialised metadata, request, response, responseHeaders, error fields to undefined in initial query state across all setResolvedQuery call sites, ensuring live getters are registered for these fields from the start
  • Removed wasted deepClone of all query state (was immediately overwritten in the loop)
  • Guarded reserved method names (run, reset, getData, getRawData, getloadingState) from being overwritten by live descriptors

🧪 How to test

  • Create a REST API query (restapi1) and a RunJS query
  • In the RunJS query, write await queries.restapi1.run(); return queries.restapi1.data — verify it returns the fresh response data, not []
  • Access queries.restapi1.error after a failed run — verify it reflects the actual error
  • Access queries.restapi1.request and queries.restapi1.response — verify they reflect the completed run's metadata
  • Verify return queries.restapi1 (returning the whole object) still works and is serialisable
  • Verify existing getData(), getRawData(), getloadingState() helper methods still work

…eries.queryName` instead of getter functions like `getData`
@johnsoncherian johnsoncherian merged commit c4ad09f into main May 11, 2026
19 checks passed
@johnsoncherian johnsoncherian deleted the fix/access-query-data branch May 11, 2026 06:31
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.

2 participants