fix: materialize nested placeholder hasOne for <HasOne> JSX#33
Open
vparys wants to merge 2 commits into
Open
Conversation
… defined ref
PlaceholderHandle only handled has-many in its field-access proxy, so a
has-one relation accessed on a placeholder entity fell through to the
scalar fallback and exposed no $entity. <HasOne field={placeholder.hasOneField}>
then called children(undefined), crashing on the first field access.
Adds an explicit has-one branch that returns a nested-placeholder
has-one handle with $entity wired to an inner PlaceholderHandle, plus
field-access proxying so chains like placeholder.profile.bio resolve to
the inner placeholder's field handle instead of undefined. Mutations
on the nested placeholder ($create/$connect) throw with a clear message,
since the outer placeholder has no backing row to attach to.
Fixes #32
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
<HasOne field={…}>over a nullable has-one relation whose parent is itself a placeholder (e.g. an outer disconnected has-one) called itschildrencallback withundefined, crashing on the first field access.PlaceholderHandle.createPlaceholderFieldHandleonly branched on has-many — has-one fell through to the scalar fallback, which has no$entity.What's in here
PlaceholderHandle.createPlaceholderFieldHandlethat returns a HasOne-shaped handle backed by a freshly created nestedPlaceholderHandlefor the inner target type.$entityresolves to the nested placeholder, and field-access proxying (placeholder.profile.bio…) forwards into it, mirroring the single-level placeholder ergonomics.$create,$connect) on a nested placeholder throw with a clear message — the outer placeholder has no backing row to attach a child to.$disconnect/$delete/$remove/$resetno-op (the relation is already disconnected). Writes to scalar fields under a nested placeholder are an explicit non-goal here; the issue only asks for the read path to stop crashing.tests/react/jsx/HasOneNullRelation.test.tsx(Article → Author=null → Profile chain). It fails onmainwithTypeError: undefined is not an objectand passes with the fix.Test plan
bun test tests/react/jsx/HasOneNullRelation.test.tsx— passesbun test tests/react/relations/hasOne/ tests/react/jsx/— 87 pass, 0 failbun testwhole suite — same 9 pre-existing failures as onmain(Storybook stories + one unrelated form has-many dirty-state test), no new regressionsbun run typecheck— cleanFixes #32