solidjs / solid-router

A universal router for Solid inspired by Ember and React Router
MIT License
1.1k stars 137 forks source link

Actions called in onMount (or first run effect) are destroyed by start process, and do not receive values nor errors #433

Closed apatrida closed 3 weeks ago

apatrida commented 1 month ago

Describe the bug

Calling an action (useAction) in onMount is destroyed by a post-hydration process and break their ability to receive values or trap exceptions.

https://discord.com/channels/722131463138705510/910635844119982080/1245271486881857638

and the reproducible case linked: https://stackblitz.com/edit/github-hzq3du-fznnvu?file=src%2Fcomponents%2FHomeRoute.tsx

(note that it can work the first run or after HMR, so use refresh to see the fail)

This case fails (see console logs). Work arounds:

  1. a slight delay in timer before executing action.
  2. lazy load route

both might be fragile as not sure timing is deterministic.

Specific cause mentioned in discord: https://discord.com/channels/722131463138705510/910635844119982080/1245278570104754228

Your Example Website or App

https://stackblitz.com/edit/github-hzq3du-fznnvu?file=src%2Fcomponents%2FHomeRoute.tsx

Steps to Reproduce the Bug or Issue

  1. create action that returns value or throws exception
  2. wrap with useAction and useSubmission
  3. call in onMount
  4. log in effect the state, value, and error of the action
  5. show in JSX results and error state of action

note the logs and display are incorrect, actions goes to undefined.

Expected behavior

The action works as normal. Values and errors come back to the tracked submission.

Screenshots or Videos

No response

Platform

All day long, everywhere

Additional context

No response

apatrida commented 1 month ago

Tested again with 1.0.1 and router 0.13.4, no change.

apatrida commented 1 month ago

Tested again on 1.0.1 and router 0.13.5, no change.

Brendonovich commented 1 month ago

This happens both when first loading a page and also when navigating to it from another route. It appears that it's caused by the createRenderEffect that handles browser back/forward (native) navigations firing too eagerly, wiping out the submissions array when it shouldn't since native navigations aren't being performed. Am working on a fix.

ryansolid commented 3 weeks ago

Thanks. Looks to be fixed 0.13.6. I didn't realize it because I botched the 0.13.3 release.. but there was a PR in there #405 that broke a bunch of stuff unintentionally and I believe are back to a good place now.