vaadin / hilla

Build better business applications, faster. No more juggling REST endpoints or deciphering GraphQL queries. Hilla seamlessly connects Spring Boot and React to accelerate application development.
https://hilla.dev
Apache License 2.0
911 stars 57 forks source link

ListSignal insertLast fails if used before reading value #2852

Open krissvaa opened 21 hours ago

krissvaa commented 21 hours ago

Describe the bug

Trying to insert value into list signal before reading the value for the first time always fails with an error:

Caused by: java.lang.IllegalStateException: Signal not found for client signal: 7r5ynGjRRkDNyqwdhU23X at com.vaadin.hilla.signals.handler.SignalsHandler.update(SignalsHandler.java:94)

Expected-behavior

Insert should work everytime

Workaround is to read the list signal value before inserting any values

effect(() => { 
    listSignal.value;
});

Reproduction

Project to reproduce: my-app-listsignal.zip

System Info

Hilla: 24.6.0.alpha1

Legioth commented 21 hours ago

Sounds like a duplicate of https://github.com/vaadin/hilla/issues/2701 which was fixed last week but the fix is not yet in the latest alpha release.

taefi commented 20 hours ago

There could be a small problem that needs investigation: The fix we merged last week might still not work for a specific case: If a ListSignal is conditionally rendered, e.g. checking the items.length === 0 to show a placeholder message such as "no items yet..." and the user does not interact with it, the signal may never subscribe to receive the updates that triggers renders.

Legioth commented 19 hours ago

Why does items have a length property? Should work properly if you do items.value.length since you're then actually reading the signal's value. As we discussed at some point previously, we should prefer to "force" the developer to use .value to make the signal relationship clear rather than providing shorthands.

taefi commented 18 hours ago

We can close this as duplicate.