Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayInput has different behaviour in dev and in build #9617

Open
PedroPerpetua opened this issue Jan 26, 2024 · 2 comments
Open

ArrayInput has different behaviour in dev and in build #9617

PedroPerpetua opened this issue Jan 26, 2024 · 2 comments
Labels

Comments

@PedroPerpetua
Copy link

The ArrayInput component has a breaking different behaviour in the dev environment and when you actually build the project; an empty ArrayInput (that has not been interacted with) will:

  • Return an empty array in dev
  • Return undefined in the build

Note: interacting with it in the build version (adding an entry) but still leaving it empty (removing all entries before submitting) will return an empty array too, as expected.

What you were expecting:

Both environments should behave the same way, preferably returning an empty array in both.

What happened instead:

Inside the build, a not-interacted ArrayInput returns undefined.

Steps to reproduce:

  • Have a Create Page with an ArrayInput
  • Create a new record with said page, without adding any entries to the ArrayInput
  • Submit the creation

Related code:

Since this issue requires a build, instead of a sandbox I provide a minimal reproduction example repo: https://github.com/PedroPerpetua/ra-array-input-bug

This was bootstrapped with react-admin, and replaced the dataProvider with a very simple one that will just alert information about the type received from the ArrayInput, alongside a CreatePage that features an ArrayInput.

The dev server can be started with yarn dev and the build created with yarn build, as per usual.

Other information:

Environment

  • React-admin version: 4.16.7 (the minimal repo uses the version included in the bootstrap, but I have verified the issue with this one too)
  • React version: 18.2.0
  • Browser: Chrome
@slax57
Copy link
Contributor

slax57 commented Feb 5, 2024

Nice catch!
I could reproduce with a fresh project created with create-react-admin.

I suspect something linked to React 18 and Strict Mode which is probably enabled in dev mode but not in the production build.

@slax57 slax57 added the bug label Feb 5, 2024
@PedroPerpetua
Copy link
Author

PedroPerpetua commented Feb 5, 2024

I belive (could be wrong) that the only change Strict Mode makes that actually could change behaviour is that it will run useEffect twice for components... maybe there's something that doesn't get initialized correctly the first time, but on the second run it finally does?

Edit: correction - not just useEffect, but all lifecycles. Relevant: https://react.dev/reference/react/StrictMode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants