Skip to content

Cannot read properties of undefined (reading 'length') #5876

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

Closed
2 tasks done
nhjjgjjg opened this issue Jan 18, 2025 · 1 comment
Closed
2 tasks done

Cannot read properties of undefined (reading 'length') #5876

nhjjgjjg opened this issue Jan 18, 2025 · 1 comment

Comments

@nhjjgjjg
Copy link

TanStack Table version

v8.20.6

Framework/Library version

SolidStart 1.0

Describe the bug and the steps to reproduce it

According to the SolidStart document https://docs.solidjs.com/solid-start/building-your-application/data-loading#data-loading-always-on-the-server orders() returns undefined

Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

no

Screenshots or Videos (Optional)

Image

Image

Do you intend to try to help solve this bug with your own PR?

None

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
@riccardoperra
Copy link
Collaborator

riccardoperra commented Jan 25, 2025

data from tanstack table should always be valuated as an array. createAsync from @solidjs/router doesn't guarantee your variable result is always present, as the result type is T | undefined if you don't pass an initial value

I think your code can be refactored with something like this

const orders = createAsync(() => getOrders(), { initialValue: [] });

const table = createSolidTable({
  get data() {
     return data()
  }
})

otherwise you can create a derived accessor that returns an empty array if your createAsync result didn't resolve the value yet

const orders = createAsync(() => getOrders());

const data = () => orders() ?? [];

const table = createSolidTable({
  get data() {
     return data()
  }
})

@nhjjgjjg nhjjgjjg closed this as completed Feb 5, 2025
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

2 participants