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

Binding Arrays - Cannot read properties of undefined (reading '0') #2949

Open
shinusuresh opened this issue Dec 3, 2024 · 5 comments
Open
Labels
bug Something isn't working hilla Issues related to Hilla

Comments

@shinusuresh
Copy link

Describe the bug

Following the documentation https://vaadin.com/docs/latest/hilla/guides/forms/binding-arrays is giving the error while trying to bind items

Error handled by React Router default ErrorBoundary: TypeError: Cannot read properties of undefined (reading '0')
    at _BinderNode.initializeValue (chunk-HYT7HGKV.js?v=b6b40b33:1386:64)
    at _BinderNode (chunk-HYT7HGKV.js?v=b6b40b33:1145:12)
    at getBinderNode (chunk-HYT7HGKV.js?v=b6b40b33:1085:12)
    at [Symbol.iterator] (chunk-HYT7HGKV.js?v=b6b40b33:1042:13)
    at ArrayModel.next (<anonymous>)
    at Function.from (<anonymous>)
    at useFormArrayPart (@vaadin_hilla-react-form.js?v=b6b40b33:202:18)
    at GroupFormView (@index.tsx:20:38)
    at renderWithHooks (chunk-SV5EQZIV.js?v=b6b40b33:11548:26)
    at updateFunctionComponent (chunk-SV5EQZIV.js?v=b6b40b33:14582:28)
    at beginWork (chunk-SV5EQZIV.js?v=b6b40b33:15924:22)
    at beginWork$1 (chunk-SV5EQZIV.js?v=b6b40b33:19753:22)
    at performUnitOfWork (chunk-SV5EQZIV.js?v=b6b40b33:19198:20)
    at workLoopSync (chunk-SV5EQZIV.js?v=b6b40b33:19137:13)
    at renderRootSync (chunk-SV5EQZIV.js?v=b6b40b33:19116:15)
    at performSyncWorkOnRoot (chunk-SV5EQZIV.js?v=b6b40b33:18874:28)
    at flushSyncCallbacks (chunk-SV5EQZIV.js?v=b6b40b33:9119:30)
    at chunk-SV5EQZIV.js?v=b6b40b33:18627:21

Expected-behavior

No error is expected while adding person

Reproduction

https://github.com/shinusuresh/hilla-form-binding-array-issue.git

System Info

Operating System: MacOS
Hilla Version: 24.5.7
Browser Type: Chrome

@shinusuresh shinusuresh added bug Something isn't working hilla Issues related to Hilla labels Dec 3, 2024
@lloydchandran
Copy link

I am also facing this problem . There is a problem with array initilization . My expectation was Model.createEmptyValue on a parent object with an array will initialize it . But it’s not happening

@lloydchandran
Copy link

@platosha . This looks like basic feature that should work out of the box. Do you see any problems in the way it got implemented ?

@platosha
Copy link
Contributor

platosha commented Dec 4, 2024

Thanks for reporting. The implementation in the project looks fine from the first glance. I'll try to reproduce and get back with more info.

@platosha
Copy link
Contributor

platosha commented Dec 4, 2024

I am also facing this problem . There is a problem with array initilization . My expectation was Model.createEmptyValue on a parent object with an array will initialize it . But it’s not happening

Small clarification by the way, Model.createEmptyValue() simply returns a value, the call alone does not change anything anywhere.

@platosha
Copy link
Contributor

platosha commented Dec 5, 2024

There is a bug in the form library around on demand initialization of nullable arrays. I'm working on a fix.

Meanwhile, as a workaround, try using Nonnull annotation. A helpful shortcut is to add it globally to the API package. Add package-info.java with the following content:

@NonNullApi
package com.example.application;

import org.springframework.lang.NonNullApi;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working hilla Issues related to Hilla
Projects
None yet
Development

No branches or pull requests

3 participants