Skip to content

[pull] main from tinacms:main#214

Merged
pull[bot] merged 2 commits into
code:mainfrom
tinacms:main
May 12, 2026
Merged

[pull] main from tinacms:main#214
pull[bot] merged 2 commits into
code:mainfrom
tinacms:main

Conversation

@pull
Copy link
Copy Markdown

@pull pull Bot commented May 12, 2026

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

joshbermanssw and others added 2 commits May 12, 2026 08:47
Fixes #6692

## Summary

Fixes a `TypeError: Cannot read properties of undefined (reading
'props')` crash in the TinaCMS admin sidebar when editing content with
**2+ levels of nested rich-text fields** containing templates.

For example, a page body (rich-text) containing a Grid template whose
`gridBody` field is itself a rich-text with a Panel template inside —
clicking the inner Panel in the visual editor crashes the form builder.

## Root Cause

`getFieldGroup` in `Form` uses `findIndex` / `slice(...).findIndex` to
locate the `"children"` and `"props"` segments in the `namePath` array.
These always search **from index 0**, so on recursive calls processing
inner rich-text fields they resolve the *outer* level's segments instead
of the current one.

When the outer and inner template elements sit at different array
indices (e.g. `children[2]` vs `children[0]`), `getIn` receives a path
that points to a non-existent element, returns `undefined`, and the next
line — `item.props` — crashes.

## Fix

Four targeted changes in the `rich-text` branch of `getFieldGroup`
(`packages/tinacms/src/toolkit/forms/form.ts`):

1. **Search from current position** — replace `findIndex` with
`indexOf('children', namePathIndex + 1)` and `indexOf('props',
childrenIndex + 1)`
2. **Null guard** — `if (!item) return formOrObjectField` for graceful
fallback on malformed content
3. **Simplify `currentPathIndex`** — `propsIndex` directly (was
`namePathIndex + Math.max(propsIndex, 3)`)
4. **Simplify recursive `namePathIndex`** — `propsIndex + 1` (was
`namePathIndex + Math.max(4, childrenIndex + propsIndex)`)

The old formulas produced correct results at the first nesting level by
coincidence (`namePathIndex = 0` made the offsets cancel out). They
break at any deeper level.

---------

Co-authored-by: Jack Pettit [SSW] <57518417+JackDevAU@users.noreply.github.com>
@pull pull Bot locked and limited conversation to collaborators May 12, 2026
@pull pull Bot added the ⤵️ pull label May 12, 2026
@pull pull Bot merged commit 723632b into code:main May 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants