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

Solid-Query example returns repositoryQuery.data is undefined #7507

Closed
dhruvy1 opened this issue Jun 1, 2024 · 4 comments · Fixed by #7709
Closed

Solid-Query example returns repositoryQuery.data is undefined #7507

dhruvy1 opened this issue Jun 1, 2024 · 4 comments · Fixed by #7709

Comments

@dhruvy1
Copy link
Contributor

dhruvy1 commented Jun 1, 2024

Describe the bug

Solid-Query example returns repositoryQuery.data is undefined

Your minimal, reproducible example

https://stackblitz.com/edit/solidjs-templates-q6qdg3?file=src%2FApp.tsx

Steps to reproduce

My guess is SolidQuery is not interacting correctly with Solid's <Suspense>

Expected behavior

updated_at should be displayed, or <div>Loading...</div> should render while loading content.

How often does this bug happen?

Every time

Screenshots or Videos

Screenshot 2024-06-02 at 1 29 06 am

Platform

  • OS: MacOS
  • Browser: Firefox

Tanstack Query adapter

solid-query

TanStack Query version

5.40.0

TypeScript version

5.3.3

Additional context

The example works as expected if i wrap it in <Show when={repositoryQuery.isSuccess}>.

So my guess is SolidQuery is not interacting correctly with Solid's <Suspense>

@TkDodo
Copy link
Collaborator

TkDodo commented Jun 7, 2024

The error I'm seeing is a different one:

chunk-3OVJGQWJ.js?v=991034ec:1661 TypeError: Cannot read properties of undefined (reading 'laast_')
    at App.tsx?t=1717789917727:41:56
    at Object.fn (chunk-GNBOLAET.js?v=991034ec:337:60)
    at runComputation (chunk-3OVJGQWJ.js?v=991034ec:786:22)
    at updateComputation (chunk-3OVJGQWJ.js?v=991034ec:769:3)
    at createRenderEffect (chunk-3OVJGQWJ.js?v=991034ec:260:5)
    at insert (chunk-GNBOLAET.js?v=991034ec:337:3)
    at get children (App.tsx?t=1717789917727:41:13)
    at Object.fn (chunk-3OVJGQWJ.js?v=991034ec:1796:49)
    at runComputation (chunk-3OVJGQWJ.js?v=991034ec:786:22)
    at updateComputation (chunk-3OVJGQWJ.js?v=991034ec:769:3)

@dhruvy1
Copy link
Contributor Author

dhruvy1 commented Jun 8, 2024

@TkDodo apologies there was a typo in my stackblitz playground

Here is an updated link without the laast typo.
Please click refresh within stackblitz as it shows inconsistent result on the first load.

It should match the TanQuery example:

image

https://stackblitz.com/edit/solidjs-templates-q6qdg3?file=src%2FApp.tsx

@antonio-pas
Copy link

antonio-pas commented Jul 8, 2024

When you access repositoryQuery.data, the promise has not resolved yet because Suspense creates the elements immediately. You need to add a ? to make sure repositoryQuery.data exists. The Solid documentation on Suspense does a good job of explaining it:

const MyComponentWithSuspense = () => {
  const [profile] = createResource(async () => {
    /* fetcher code here */
  })
  return (
    <Suspense fallback={<div>fetching user data</div>}>
      <div>{profile()?.name}</div>
      <div>{profile()?.email}</div>
    </Suspense>
  )
}

In this case, the divs are created immediately, but instead of being attached to the document body, the fallback is shown.

The example at the top of the page using createResource will give an error as well, it should be updated to this:

    <div>
      <div>Static Content</div>
      <ErrorBoundary fallback={<div>Something went wrong!</div>}>
        <Suspense fallback={<div>Loading...</div>}>
        {/* needs the new ? */}
         <div>{repository()?.updated_at}</div>
        </Suspense>
      </ErrorBoundary>
    </div>

@dhruvy1
Copy link
Contributor Author

dhruvy1 commented Jul 10, 2024

Thanks for the pick up @antonio-pas I have created a PR to fix this in docs.

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

Successfully merging a pull request may close this issue.

3 participants