-
Notifications
You must be signed in to change notification settings - Fork 55
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
Signal does not work along well with iterated components that do not have key attribute #2477
Comments
Simplified reproduction case: import { useSignal } from '@vaadin/hilla-react-signals';
export default function EmptyView() {
const s = useSignal('signal');
return <>
{[1].map(x => <span>{x}</span>)}
</>
} It seems like this issue only happens in association with HMR and only for some types of changes. It happens if you load the view, and then change the array to |
Does adding a key solve the issue? I think that keys are necessary when iterating in React. |
It is not mandatory. React prints warning in dev mode. The key is used for performance optimization to check if the node is updated. https://react.dev/learn/rendering-lists. Adding a key to elements solves the issue. |
Well, that documentation also states that
|
It's irrelevant whether That's also why I'm not sure about the |
For me this worked as a workaround, but not sure if this is problematic with items, that have no id yet. Maybe the array index would be better here? {Array.from(model.mySubItems, ({model: sModel, value}) => <MyFormPart key={value?.id} model={sModel}/>)} |
The whole point of the |
The exception happens when I add a key to a loop item and the exception is unclear about what goes wrong Screen.Recording.2024-10-04.at.15.22.49.mov |
The impact of this issue is very high, the app is unusable, and there is no clear answer as to why from user's perspective |
I just hit this issue, and for a React novice trying to use Hilla which has practically no docs on how to do simple things like loop over some list it's a complete 🤯 :headbang: timewaste with an error that takes you on the wrong track completely. You can code the thing, and it works, but when you touch the code or use Copilot to e.g align a thing it explodes. |
Describe the bug
Page render throws
Rendered fewer hooks than expected. This may be caused by an accidental early return statement.
exception if your view has a signal definition and iterated components do not have keys. Internal conversation: https://vaadin.slack.com/archives/C0743B4BD5K/p1716545183155989Expected-behavior
Not using the key property is something react warns user about. It is not mandatory to use it so signals should work with non-key attributed iteration. A better warning message would also be acceptable in my opinion since not using key is not recommended.
Reproduction
Add following code to your view and do some file changes to render the page.
System Info
The text was updated successfully, but these errors were encountered: