#Transition state getting lost after an await inside ResourceFetcher

8 messages · Page 1 of 1 (latest)

hidden trout
#

https://playground.solidjs.com/anonymous/c2f53a7d-9e76-4711-8e81-aa6bc2de12c6
Check the above link to see it in action

Say if we have the following signal

const [show, setShow] = createSignal(false);

And if we call setShow(true) within startTransition

startTransition(() => setShow(true));

And somewhere inside ResourceFetcher the value of show() is different above & below an await point as shown below

  console.log('show=', show()); // true
  await new Promise((r) => setTimeout(r, 1));
  console.log('show=', show()); // false !!!
olive spear
#

If you do use an actual resource with createResource then transitions will work correctly

#
const Greeting = lazy(async () => {
  createResource(show, async show => {
    console.log('show=', show);
    await new Promise((r) => setTimeout(r, 3000));
    console.log('show=', show);
  })
  return import("./tab1");
});
#

this works

hidden trout
olive spear
#

Any signals the resource depends on you need to pass it as a source because suspense with transitions creates a fork of all the sources

#

If you don't pass it as a source, nothing stops the signal from changing

#

You can pass multiple sources like () => [a(), b()]