Thinkmill / Thinkmill/keystatic

setState infinite loop on deep nested arrays

Open
#827 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
2.4k
Forks
159
Avg merge
21h 41m
Merged PRs (30d)
2

Description

I've encountered the following error when editing a singleton with deep nested arrays:

Unhandled Runtime Error

Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.

How to replicate: This error only occurs when I'm three nested arrays deep and I add a new item, click Done and then re-enter the second array item and try to add a new item to the third array.

Here's a Loom video demonstrating the issue

Here's my singleton schema (simplified):

menus: singleton({
      label: "Menus",
      path: "content/menus/",
      schema: {
        title: fields.text({
          label: "Title",
        }),
        menus: fields.array(
          fields.object({
            title: fields.text({
              label: "Title",
            }),
            description: fields.text({
              label: "Description",
              multiline: true,
            }),
            menuSections: fields.array(
              fields.object({
                title: fields.text({
                  label: "Title",
                }),
                menuItems: fields.array(
                  fields.object({
                    title: fields.text({
                      label: "Title",
                    }),
                    description: fields.text({
                      label: "Description",
                      multiline: true,
                    }),
                  }),
                  {
                    label: "Menu Items",
                    itemLabel: (props) => props.fields.title.value,
                  }
                ),
              }),
              {
                label: "Menu Sections",
                itemLabel: (props) => props.fields.title.value,
              }
            ),
          }),
          {
            label: "Menus",
            itemLabel: (props) => props.fields.title.value,
          }
        ),
      },
    })

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the singleton editor scenario with three nested arrays, adding an item, clicking Done, and re-entering the second item. Trace the setState updates involved in the third-level array; done means this sequence no longer reaches React's maximum update depth error.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.