hilla icon indicating copy to clipboard operation
hilla copied to clipboard

ListSignal insertLast fails if used before reading value

Open krissvaa opened this issue 1 year ago • 4 comments
trafficstars

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

krissvaa avatar Oct 21 '24 10:10 krissvaa

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.

Legioth avatar Oct 21 '24 10:10 Legioth

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.

taefi avatar Oct 21 '24 11:10 taefi

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.

Legioth avatar Oct 21 '24 11:10 Legioth

We can close this as duplicate.

taefi avatar Oct 21 '24 13:10 taefi