fix(dropdown): keep query-sourced selections while the options query loads - #3330
Open
alecrt wants to merge 1 commit into
Open
fix(dropdown): keep query-sourced selections while the options query loads#3330alecrt wants to merge 1 commit into
alecrt wants to merge 1 commit into
Conversation
…loads
A dropdown can mix a static `dropdown_option` child (typically an "All"
entry) with options coming from `data=`. `isDropdownValueValid` switched
validation on as soon as static options existed, so before the query
returned the known universe was just the static values — and any legitimate
query-sourced selection was cleared.
The visible damage is on URL-hydrated values: `?status=active` on a page
whose dropdown declares `{% dropdown_option value="%" %}` and pulls the rest
from a query resets to empty on first paint, and the writer then drops the
parameter from the URL too, so the link is not shareable. `initial_value`
suffers the same fate whenever it names a query-sourced option.
Adds an explicit "options query configured but not settled" state: while it
holds, the value is kept whatever the static options say. Validation resumes
untouched once the query lands, so the genuine stale-selection case that
cascading dropdowns rely on still clears. A pending query that errored is
treated the same way, which is the conservative reading already documented
for the empty-result case: keeping a selection we cannot check beats
clearing one that was valid.
Dropdowns with no query at all are unaffected — there is no pending state,
so static options validate exactly as before.
Co-authored-by: Cursor <cursoragent@cursor.com>
|
@alecrt is attempting to deploy a commit to the Evidence Team on Vercel. A member of the Team first needs to authorize it. |
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.
Summary
Prevents single-select and multi-select dropdowns from prematurely clearing query-sourced selections when static
dropdown_optionchildren (e.g. an "All" option) are present, ensuring URL-hydrated filter values andinitial_valueselections survive initial page hydration while options are loading.Problem / Motivation
A dropdown often mixes static
dropdown_optionchildren (typically an "All" or default entry) with dynamic options populated fromdata=:Currently,
isDropdownValueValid(core/src/user-components/tags/dropdown/validation.ts) switches validation on as soon as static options exist (hasStaticOptions). Because the options query has not resolved on first paint,availableValuesonly contains the static options.What went wrong:
?category=electronics) fails validation against the static option set alone and is cleared on initial mount.initial_valuesuffers the same failure whenever it refers to a query-sourced value.Solution
optionsQueryPendingstate (queryConfig !== undefined && optionsQuery.result === undefined) indicating that an options query is configured but has not yet produced a result.optionsQueryPendingistrue,isDropdownValueValidpreserves the current selection regardless of static options.Testing
core/src/user-components/tags/dropdown/validation.test.ts:keeps a query-sourced value while the options query is still pending, despite static optionsvalidates again as soon as the options query settlesleaves dropdowns without a query untouched: no pending state, static options still validatepnpm --filter @evidence/core check: 0 errors.Checklist
core/**(no files at repository root).