Fix boolean arg types parsing and encoding #21102
Merged
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.
Closes #20960
What I did
Convert string boolean type to boolean type.
How to test
yarn task --task sandbox --start-from auto --template react-vite/default-ts
ADDONS controls/basics/Undefined
storytrue
orfalse
, instead of"true"
or"false"
Rationale
When the current serialization/parsing logic for URLs was implemented, we mostly relied on argTypes to be able to parse things back to the correct type. However, those types aren't always available or might be a union type (e.g. string | number) so that's insufficient. We introduced
!null
and!undefined
and those color things in order to be able to represent those in the URL (how else could you?).We assumed booleans would be handled via argTypes, so we did not introduce a special serialization syntax for those.
Of course, we considered the various standard serialization syntaxes, including JSON. However, JSON is actually a terrible fit for URLs because it uses quotes all over the place (which are super ugly in URLs) and simply removes undefined values as if they were never there (try JSON.stringify({ foo: undefined })). So we decided to stick with what qs provides and build a dialect on top to handle these special data types.
In this PR, we continue to use our own dialect on top of qs to support also
boolean
values. This solution of course isn't bug-free (the string!true
will be converted into a boolean `true) We consider this as an absolute edge-case. In the future, we might revisit this decision to use JSON parsing instead (although we would sacrifice readability).Checklist
MIGRATION.MD
Maintainers
make sure to add the
ci:merged
orci:daily
GH label to it.["cleanup", "BREAKING CHANGE", "feature request", "bug", "documentation", "maintenance", "dependencies", "other"]