Repository navigation
feat(core): support the same query with different variables in useFaustQuery - #2695
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
🟡 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
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.


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.