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

useLoaderState returns undefined after router.invalidate() is called #2846

Open
datner opened this issue Nov 24, 2024 · 0 comments
Open

useLoaderState returns undefined after router.invalidate() is called #2846

datner opened this issue Nov 24, 2024 · 0 comments

Comments

@datner
Copy link

datner commented Nov 24, 2024

Which project does this relate to?

Start

Describe the bug

Following the Getting Started guide this snippet is presented for copy-pasting:

function Home() {
  const router = useRouter()
  const state = Route.useLoaderData()

  return (
    <button
      type="button"
      onClick={() => {
        updateCount({ data: 1 }).then(() => {
          router.invalidate()
        })
      }}
    >
      Add 1 to {state}?
    </button>
  )
}

upon clicking the button, you are presented with "Add 1 to ?" in the UI. Refreshing the page presents the expected number.
Inspecting state shows that once the component rerenders, supposedly due to router.invalidate, it returns undefined.
Placing a console.log in the loader shows that its executed on page load and then never again, regardless of invalidation.

Your Example Website or App

None. The examples don't work, stackblitz won't let me fork the examples either.

Steps to Reproduce the Bug or Issue

  1. follow the Getting Started guide to the end
  2. fix the index.tsx not working because browsers remove trailing / for root routes making it unreachable since it's exact by changing it to something like home.tsx
  3. click on Add 1 to ?
  4. refresh the page
  5. click on Add 1 to 1?
  6. It becomes Add 1 to ?

Expected behavior

router.invalidate triggers another call to the route loader, and useRouteState does not return undefined

Screenshots or Videos

Image

Platform

  • OS: macOS
  • Browser: Arc
dependencies:
@tanstack/react-router 1.82.2
@tanstack/router-devtools 1.82.2
@tanstack/start 1.82.6
react 18.3.1
react-dom 18.3.1
vinxi 0.4.3

devDependencies:
@tanstack/router-plugin 1.81.9
@types/react 18.3.12
@types/react-dom 18.3.1
@vitejs/plugin-react 4.3.3
vite 5.4.11

Additional context

I've encountered multiple bugs immediately out of the gate without even starting to write any code of my own.
I know it's beta, but that was a bit rough even for beta imho..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant