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

Panic on write to nested Vec in a Store #3338

Closed
purung opened this issue Dec 8, 2024 · 6 comments
Closed

Panic on write to nested Vec in a Store #3338

purung opened this issue Dec 8, 2024 · 6 comments
Labels
bug Something isn't working

Comments

@purung
Copy link
Contributor

purung commented Dec 8, 2024

Describe the bug
I tried using a nested <For> with a Store. However, when I write to the inner Vec I get a wasm panic in the browser.

I think this would be the same as if I had a Vec<Tag> on a Todo, and tried using outer.inner().write().push(new) as in the stores example to extend the Tag list.

Leptos Dependencies

Starter axum template, 0.7 + reactive_stores, nightly.

Minimal example: https://github.com/purung/stores_inner_error

Expected behavior
I am sure I am missing something, but I would have expected this to work since stores are about ergonomics with nested structure, and I used methods shown in the example. Or, a compiler error.

Error output

storestest.wasm:2808272:1
    ha14370bbf30ccd11 http://localhost:3000/pkg/storestest.wasm:2808272
    h95b597a01bd9daef http://localhost:3000/pkg/storestest.wasm:945930
    h552e73743194e10d http://localhost:3000/pkg/storestest.wasm:2473618
    ha062b0945442f7c0 http://localhost:3000/pkg/storestest.wasm:449903
    storestest.wasm.<reactive_stores::keyed::AtKeyed<Inner,Prev,K,T> as reactive_stores::store_field::StoreField>::reader::h455912315912b83c http://localhost:3000/pkg/storestest.wasm:858638
    storestest.wasm.<reactive_stores::arc_field::ArcField<<T as core::ops::index::Index<usize>>::Output> as core::convert::From<reactive_stores::keyed::AtKeyed<Inner,Prev,K,T>>>::from::{{closure}}::hf9f0c381b0482ab7 http://localhost:3000/pkg/storestest.wasm:2394984
    storestest.wasm.<reactive_stores::arc_field::ArcField<T> as reactive_stores::store_field::StoreField>::reader::hfeffe2d13c428f77 http://localhost:3000/pkg/storestest.wasm:2179627
    storestest.wasm.<reactive_stores::field::Field<T,S> as reactive_stores::store_field::StoreField>::reader::{{closure}}::he2fab88640fe124a http://localhost:3000/pkg/storestest.wasm:2588176
    h9329b9d965df7527 http://localhost:3000/pkg/storestest.wasm:1782641
    storestest.wasm.<reactive_stores::field::Field<T,S> as reactive_stores::store_field::StoreField>::reader::hb757e29258931c78 http://localhost:3000/pkg/storestest.wasm:2250249
    storestest.wasm.<reactive_stores::keyed::KeyedSubfield<Inner,Prev,K,T> as reactive_stores::store_field::StoreField>::reader::h678049d17d4a97f4 http://localhost:3000/pkg/storestest.wasm:1630721
@purung purung changed the title Cannot push to nested Vec in a Store Panic on write to nested Vec in a Store Dec 8, 2024
@gbj
Copy link
Collaborator

gbj commented Dec 8, 2024

I have not looked into this fully yet.

However, something occurs to me right away: You are generating UUIDs as keys, and you start with items in both the Outer and Inner structures. However, you're also using SSR + hydration, which means that the code runs on both sides. As a result, you are generating different UUIDs: the data in the list is different on the server from the client.

Like I said, I have no idea if this is related and I have not tried running the example, it just occurs to me as I look at the code.

@purung
Copy link
Contributor Author

purung commented Dec 8, 2024

A very reasonable question, and my first thought was that the Uuids might have had something to do with it. I did, however, observe the error with fixed usize as well. I just happened to settle on uuid in this example. It's closer to my use case, which you can see it in a help thread on discord if you like. Thanks for looking into it when you have time 😊

@gbj gbj added the bug Something isn't working label Dec 10, 2024
@gbj
Copy link
Collaborator

gbj commented Dec 10, 2024

Having played around for an hour or so this evening, I do think that there is simply an issue with nested keyed fields at the moment. I will try to find some time to look at it in more depth in the upcoming weeks.

@purung
Copy link
Contributor Author

purung commented Dec 10, 2024

I appreciate the time you put in to making this work, when you have it to spare 🙏

@gbj
Copy link
Collaborator

gbj commented Dec 10, 2024

As is so often the case, sleeping on it for a night and coming back to it made all the difference. #3344 should fix this issue: I tested it against your example and it seems to work correctly but let me know if that's not the case.

@gbj gbj closed this as completed in e65969c Dec 12, 2024
@purung
Copy link
Contributor Author

purung commented Dec 12, 2024

That's fantastic! I haven't managed to test it in my project yet, but the minimal example should suffice to be confident.

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

No branches or pull requests

2 participants