-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Comments
Nice catch! I suspect something linked to React 18 and Strict Mode which is probably enabled in dev mode but not in the production build. |
I belive (could be wrong) that the only change Strict Mode makes that actually could change behaviour is that it will run Edit: correction - not just |
I confirm the bug still exists in V5. Reproduction: https://github.com/fzaninotto/ra-array-input-bug |
The production behavior is the correct one: if you don't define a default value, it is set to In any case, if you need the default value to be an empty array in production, you can always use the - <ArrayInput source="array_input">
+ <ArrayInput source="array_input" defaultValue={[]}>
<SimpleFormIterator>
<TextInput source="text_input" />
</SimpleFormIterator>
</ArrayInput> As there is an easy workaround, we're considering this a low-priority bug. |
I can't replicate with react-hook-form alone (see codesandbox), so it indeed seems to be a react-admin issue. |
React-hook-form sets the value to Note that this default value isn't detected by a export const FormInspector = () => {
const { getValues } = useFormContext();
React.useEffect(() => {
console.log('Form values:', getValues());
});
return null;
}; For some reason, react-admin removes this default value shortly after mount. |
The
ArrayInput
component has a breaking different behaviour in the dev environment and when you actually build the project; an emptyArrayInput
(that has not been interacted with) will:undefined
in the buildNote: 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
returnsundefined
.Steps to reproduce:
ArrayInput
ArrayInput
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 withyarn build
, as per usual.Other information:
Environment
The text was updated successfully, but these errors were encountered: