fix(OmegaForm): deep-fill defaults for nullable nested structs#759
Merged
Conversation
When a S.NullOr(S.Struct(...)) field materialises, its untouched nullable siblings are normalized to null (or their schema default) in the live form state, during validation and during decoding — instead of being rejected as "field must not be empty".
@effect-app/cli
effect-app
@effect-app/eslint-codegen-model
@effect-app/eslint-shared-config
@effect-app/infra
@effect-app/vue
@effect-app/vue-components
commit: |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes OmegaForm submission/validation failures caused by S.NullOr(S.Struct(...)) fields “materializing” mid-edit (after one child is filled) while their untouched nullable siblings remain undefined and fail strict S.NullOr(...) decoding/validation.
Changes:
- Add
fillNestedDefaults(AST walk) to backfill missing nullable children (to schema defaults ornull) only for structs reached through nullable unions. - Normalize values before validation and decoding, and keep live form state consistent by invoking normalization after field changes.
- Add regression/unit tests plus a Storybook story and a changeset.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/vue-components/stories/OmegaForm/NullableNestedStruct.vue | New story demonstrating nullable nested-struct materialization behavior. |
| packages/vue-components/stories/OmegaForm.stories.ts | Registers the new NullableNestedStruct story. |
| packages/vue-components/src/components/OmegaForm/useOmegaForm.ts | Normalizes values for schema validation/decoding; adds live-state normalization hook on the form instance. |
| packages/vue-components/src/components/OmegaForm/types.ts | Exposes normalizeNullableStructs() on the OmegaForm API type. |
| packages/vue-components/src/components/OmegaForm/OmegaInternalInput.vue | Calls form.normalizeNullableStructs() after field changes to keep values consistent. |
| packages/vue-components/src/components/OmegaForm/meta/defaults.ts | Implements fillNestedDefaults AST-based backfilling for materialized nullable structs (reference-preserving). |
| packages/vue-components/tests/OmegaForm/NullableNestedStructValidation.test.ts | Regression test proving submission succeeds with only one nullable child filled; untouched struct remains null. |
| packages/vue-components/tests/OmegaForm/Defaults.values.test.ts | Unit tests for fillNestedDefaults behavior (tagged unions, arrays, reference preservation). |
| .changeset/omega-nullable-nested-struct.md | Patch changeset entry for @effect-app/vue-components. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Problem
A
S.NullOr(S.Struct(...))field has no slot in the form value until a child is filled. Once it materialises (the user fills one child), its untouched nullable siblings are stillundefined— which strictS.NullOr(...)children reject with a spurious "field must not be empty" error, blocking submission.Fix
New
fillNestedDefaults(AST walk) backfills the untouched children of a materialised nullable struct with their schema default (ornull). Applied in three places:normalizeFormValue, so submit/validate see the normalized value;normalizeNullableStructs()is called fromOmegaInternalInput.handleChange(the only point a struct can materialise), sovaluesstays consistent. No perpetualwatch.The always-present root struct is left untouched; only children reached through a nullable union are filled. Discriminated unions are matched by
_tag; ambiguous unions are left alone.Tests
Defaults.values.test.ts— unit tests forfillNestedDefaults(materialised struct, tagged-union safety, array elements, reference-preservation).NullableNestedStructValidation.test.ts— regression repro: submits when only one child of a nullable struct is filled; keeps an untouched struct asnull.