question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Infinite loop if initialValue is defined in a SelectArrayInput which is integrated in a formdataconsumer

See original GitHub issue

What you were expecting: Defined initial values for SelectArrayInput in a FormDataConsumer and have a working environment

What happened instead: An infinite loop take place and stop application.

Steps to reproduce:

  • Go to https://codesandbox.io/s/sweet-darkness-15q1m?file=/src/posts.js:1446-1462
  • Open your browser inspector
  • Go in the integrated browser to post/create
  • You should see “Warning: Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn’t have a dependency array, or one of the dependencies changes on every render.” in the console
  • Choose nom 2 in the first select
  • You should see an infinite loop and real browser (firefox at least) ask to stop the process

Related code:

<SimpleForm>
      <FormDataConsumer>
        {({ formData, ...rest }) => {
          return (
            <SelectArrayInput
              label="User"
              source="userId"
              initialValue={[1]}
              choices={[
                { id: 1, name: "nom1" },
                { id: 2, name: "nom2" },
                { id: 3, name: "nom3" },
                { id: 4, name: "nom4" }
              ]}
            >
              <ChipField source="name" />
            </SelectArrayInput>
          );
        }}
      </FormDataConsumer>
      {/*...*/}
</SimpleForm>

Other information:

Environment

  • React-admin version: 3.10.2
  • React version: 17.0.1
  • Browser: firefox & chrome tested
  • Stack trace (in case of a JS error):

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
djhicommented, Jun 28, 2021

Nevermind, the original sandbox still shows the issue indeed.

1reaction
Nunobpintocommented, Jun 28, 2021

I’m still experiencing this bug as well as of react-admin@3.16.4, why is it closed?

Read more comments on GitHub >

github_iconTop Results From Across the Web

React hooks depends on another state can cause infinite loop ...
I think it is happening because of useEffect dependency array . In the infinite loop version of useEffect , initialValue is changing ...
Read more >
Input Components - React-admin - Marmelab
An Input component displays an input, or a dropdown list, a list of radio buttons, etc. Such components allow to update a record...
Read more >
An infinite loop may occur in Ladder Diagram (LD) and ...
When the ISaGRAF runtime is executing in an infinite loop, the controller in which the ISaGRAF runtime is embedded stops scanning inputs and ......
Read more >
ra-input-rich-text: Versions - Openbase
Fix <FormDataConsumer> inside <SimpleFormIterator> adds empty value (#8061) (fzaninotto) ... Fix DOM warnings when using <SelectArrayInput> as child of ...
Read more >
How to solve the React useEffect Hook's infinite loop patterns
Solve the issue of infinite loops when using the useEffect Hook in React to more smoothly utilize the Hook for your app's side...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found