solid / start : `createAsync`/`createResource` mixes results when run server side, when component has "unstable" execution. due to secondary rerun of the suspended component.
Describe the bug
createAsync/createResource mixes results when run server side, when component has "unstable" execution. due to secondary rerun of the suspended component. and incorrect mapping.
Your Example Website or App
https://stackblitz.com/edit/github-52yqwfhu-kryvpmtc?file=src%2Froutes%2Fx.tsx,src%2Froutes%2Fabout.tsx
Steps to Reproduce the Bug or Issue
- go directly to the
/aboutin the browser not via the link - observe the logs
Expected behavior
if (shouldRedirect()) {
console.log('LATER');
console.log('A:', aAsy()); // expected "A: a" actual "A: b"
console.log('B:', bAsy()); // expected "B: b" actual "B: a"
} else {
console.log('INITIAL');
console.log('A:', aAsy()); // should be undefined
console.log('B:', bAsy()); // should be undefined
}
Screenshots or Videos
https://github.com/user-attachments/assets/d9290ce8-3da1-412c-8370-4c4ba3d9b655
Platform
online playground
Additional context
if (shouldRedirect()) {
// later
// if we flip back the order it will become stable again
aAsy = createAsync(() => a());
bAsy = createAsync(() => b());
// bAsy = createAsync(() => b());
// aAsy = createAsync(() => a());
} else {
// initial
bAsy = createAsync(() => b());
aAsy = createAsync(() => a());
}
solid re runs the suspended component on the 2nd run it tries to match the results based on the original (initial) order of requests.
because we flip the createAsync order on the "later" phase the results are matched incorrectly.
this is the playground with the stable example https://stackblitz.com/edit/github-52yqwfhu-whw2w4gw?file=src%2Froutes%2Fabout.tsx
I Created a simplified repro to show the issue and its implications
https://stackblitz.com/edit/github-52yqwfhu-ak1xbhv6?file=src%2Froutes%2Fabout.tsx
https://github.com/user-attachments/assets/48901a58-bb57-4f24-a90b-3cad376cf468
cc: @ryansolid
is this something that is documented or need to be documented ? what is your take on the issue can it be fixed in solid 1.x
is it going to be a problem in solid 2.x ?
Yeah it should be documented. Because of the way we do re-renders during SSR it's the only primitive that suffers from "hook" rules and only during SSR. In 2.0 the pull-based system won't have this problem.
Maybe we move the issue there and make it a documentation issue because we won't be able to fix this in 1.0 design.