[pull] main from tinacms:main#214
Merged
Merged
Conversation
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>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
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 : )