Error when using "createResource" as global.

So, look at the image. On it you see that the Resource is global scoped. But i got the error "Cannot use 'in' operator to search for 'data' in undefined", it's a bug? How i can fix this "bug", because when i do many same resources, it's fetches all of them, and so big load on server... I tried some things, like using the "createRoot", or "resource.latest", it's not working. I don't know english so good, because i am living in country, with different language πŸ™‚.
No description
7 Replies
lxsmnsyc
lxsmnsycβ€’5mo ago
createResource is intended to be declared inside the components because of some internal stuff the SSR manages (one of this is unique id generation, which is tied to the SSR's instance)
нашол Π±Π°ΠΌΠΆΠ° Π² курятника!
Oh, so i can't solve this problem by another way?
lxsmnsyc
lxsmnsycβ€’5mo ago
no sorry. The closest you'll get is a createResource at your root component
Madaxen86
Madaxen86β€’5mo ago
Or use createAsync inside any component you need and wrap resdata in the cache function of solid router which will dedupe requests, meaning there will only be one fetch call no matter how many components fetch resdata with createAsync. See the solid start docs for data loading: https://docs.solidjs.com/solid-start/building-your-application/data-loading#data-loading-always-on-the-server
нашол Π±Π°ΠΌΠΆΠ° Π² курятника!
Thanks you so much) it works! But why createAsync doesn't trigger Suspence, when i call "revalidate" method? How i can fix that?
Madaxen86
Madaxen86β€’5mo ago
Well createAsync and Suspense are actually made to work together like charm… Suspense will display the β€žpastβ€œ while the new data is being fetched due to its unblocking nature. Hereβ€˜s a codesandbox that shows that behaviour when you switch the tab: https://codesandbox.io/embed/solid-suspense-tabs-vkgpj?file=/src/index.js&codemirror=1
Solid Suspense Tabs - CodeSandbox
Solid Suspense Tabs by ryansolid using babel-preset-solid, solid-js
Want results from more Discord servers?
Add your server