Skip to content

feat(core): support the same query with different variables in useFaustQuery - #2695

Merged
josephfusco merged 7 commits into
canaryfrom
feat/1742-faust-query-variables
Oct 23, 2026
Merged

josephfusco merged 7 commits into
canaryfrom
feat/1742-faust-query-variables

Conversation

@josephfusco

Copy link
Copy Markdown
Member

Fixes #1742

useFaustQuery(query) without variables still returns the last result as before, and each result is stored once in the page props (the query-only entry records which variables it was fetched with instead of being copied), so existing templates send the same amount of data.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Assisting with the storage and lookup of query results by variables, the tests and the docs.

@josephfusco josephfusco added [Area] Core Issues for the @faustwp/core package [Type] Enhancement A suggestion for improvement of an existing feature labels Oct 22, 2026
@josephfusco
josephfusco marked this pull request as ready for review October 22, 2026 19:44
@josephfusco
josephfusco requested review from a team and colinmurphy as code owners October 22, 2026 19:44
@josephfusco
josephfusco requested a balanced review from Copilot October 23, 2026 14:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Result indexing can return incorrect data, and existing client-query mocks are incompatible with the new promise handling.

3 open issues
What changed in this PR

Adds variable-specific result lookup to useFaustQuery, addressing #1742 while preserving the existing query-only lookup behavior.

Changes:

  • Introduces shared storage and lookup helpers for query results keyed by variables.
  • Integrates the helpers into server-side and browser-side template fetching.
  • Exports hook options and adds tests and usage documentation.
File Description
packages/​faustwp-core/​tests/​store/​faustQueries.test.ts Tests result keys, storage, and lookup behavior.
packages/​faustwp-core/​tests/​hooks/​useFaustQuery.test.tsx Tests variable-specific and legacy hook usage.
packages/​faustwp-core/​tests/​getWordPressProps.test.ts Tests server-side storage of multiple query results.
packages/​faustwp-core/​src/​store/​faustQueries.ts Adds variable-aware result storage and retrieval.
packages/​faustwp-core/​src/​index.ts Exports the hook options type.
packages/​faustwp-core/​src/​hooks/​useFaustContext.tsx Adds optional variables to query lookup.
packages/​faustwp-core/​src/​getWordPressProps.tsx Uses shared storage for server-fetched results.
packages/​faustwp-core/​src/​components/​WordPressTemplate.tsx Uses shared storage for browser-fetched results.
docs/​how-to/​use-multiple-queries-in-a-template/​index.md Documents repeated queries with different variables.

Review effort: Balanced

Comment thread packages/faustwp-core/src/components/WordPressTemplate.tsx
Comment thread packages/faustwp-core/src/store/faustQueries.ts Outdated
Comment thread packages/faustwp-core/src/store/faustQueries.ts Outdated
@josephfusco
josephfusco merged commit 503dd16 into canary Oct 23, 2026
16 checks passed
@josephfusco
josephfusco deleted the feat/1742-faust-query-variables branch October 23, 2026 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Area] Core Issues for the @faustwp/core package [Type] Enhancement A suggestion for improvement of an existing feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multiple Queries support should support multiple of the same query with different variables/options

2 participants