feat(core,react): support nested repeats with $item in statePath#256
Open
tmchow wants to merge 1 commit intovercel-labs:mainfrom
Open
feat(core,react): support nested repeats with $item in statePath#256tmchow wants to merge 1 commit intovercel-labs:mainfrom
tmchow wants to merge 1 commit intovercel-labs:mainfrom
Conversation
Inner repeat elements can now reference the outer repeat's item data
by using { $item: "fieldName" } as statePath instead of a static
string. The repeat renderer resolves $item against the parent
RepeatScope's basePath.
Example: { repeat: { statePath: { $item: "subitems" } } } inside
an outer repeat over /companies resolves to /companies/0/subitems,
/companies/1/subitems, etc.
Applied the same statePath resolution across all renderer packages
(react, react-native, react-email, react-pdf, ink, solid, vue, image).
Fixes vercel-labs#252
Contributor
|
@tmchow is attempting to deploy a commit to the Vercel Labs 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
Adds support for nested repeats by allowing
$itemexpressions inrepeat.statePath. Inner repeat elements can now reference data from the outer repeat's current item.Changes
packages/core/src/types.ts: Widenedrepeat.statePathtype tostring | { $item: string }packages/react/src/renderer.tsx:RepeatChildrennow resolves{ $item: "field" }against the parentRepeatScope.basePathbefore reading state$itemstatePathUsage
{ "type": "Container", "repeat": { "statePath": "/companies", "key": "id" }, "children": ["company-employees"], "props": {} }{ "type": "Table", "repeat": { "statePath": { "$item": "employees" }, "key": "id" }, "children": ["employee-row"], "props": {} }The inner repeat resolves to
/companies/0/employees,/companies/1/employees, etc.Testing
All 893 tests pass (892 existing + 1 new nested repeat test).
pnpm type-checkpasses.Fixes #252
This contribution was developed with AI assistance (Codex).