Skip to content

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

Closed

Description

@apatrida

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

Activity

  1. apatrida commented on May 30, 2024

    @apatrida
    Author

    Tested again with 1.0.1 and router 0.13.4, no change.

  2. apatrida commented on Jun 1, 2024

    @apatrida
    Author

    Tested again on 1.0.1 and router 0.13.5, no change.

  3. Brendonovich commented on Jun 8, 2024

    @Brendonovich
    Contributor

    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.

  4. ryansolid commented on Jun 18, 2024

    @ryansolid
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions