Await resolution of previous routeData in nested routeData

I have a route that fetches some data.
export function routeData({ params }) {
return createRouteData(async (key) => doMyFetch(key), { key: () => params.id })
}
export function routeData({ params }) {
return createRouteData(async (key) => doMyFetch(key), { key: () => params.id })
}
In a nested route, I want to await the result of parent route data first, before doing another fetch
export function routeData({ params, data }) {
if (!data().hasAccess) return undefined
return createRouteData(async (key) => doMyOtherFetch(key), { key: () => params.id })
}
export function routeData({ params, data }) {
if (!data().hasAccess) return undefined
return createRouteData(async (key) => doMyOtherFetch(key), { key: () => params.id })
}
CSR works fine, because I navigate from the parent route and the data is available. SSR does not work. routeData apparently is running multiple times in SSR and even though my log shows that the data is there, the function still executes past the initial guard clause - probably only in the first passthrough (I get no log though :O) when the data is still undefined. How can I tell solid to wait for data() to resolve before continuing on with the function execution? I'd like to avoid wrapping everything inside memos, effects, etc., which would mess up my returntypes and adds unnecessary complexity to something that should be solvable with a simple await. I can't find any help in the docs regarding this. Thank you in advance 🙏
2 Replies
Martnart
MartnartOP2y ago
Immediately after posting I found a solution, just add if (!data()) return because it will run again when data is resolved. However, I feel I'm on thin ice here. Could anyone point me to some resource where I can read more about the lifecycle of a routeData function?
Alex Lohr
Alex Lohr2y ago
Not 100% recent, but still helpful: https://start.solidjs.com/api/createRouteData
SolidStart Beta Docuentation
SolidStart Beta Documentation
Early release documentation and resources for SolidStart Beta
Want results from more Discord servers?
Add your server