Closed ITenthusiasm closed 10 months ago
Thank you. We should wire this up. For those stuck here. You can do a default export from root.data.ts
in the meanwhile. But we should definitely support this.
Hi @ryansolid! It doesn't seem that the root.data.ts
default export is allowed to return async data, is it something planned?
(my use case is to set the <Html lang={lng}>
lang attribute based on the saved user session in the db, but I am not sure there is a good way to use async data for the root <Html>
attributes)
This would be extremely useful. I want to have a component in root so I can show "You are logged in as {user}" on every page. At the moment this is only possible with client side rendering.
@benoitv-code the async data call should be wrapped inside createResource(async () => {}) like the normal routeData
function does.
@ryansolid I suggest adding some documents about the root.data.ts
. It took really a while for me to correctly put my server side graphql request in side root.data.ts
along with the cookie.
@hardywu Can you show me more about how you achieved that? I tried using createResource
within root.data.ts
but the root component always starts rendering before the promise has resolved. I just can't get server side root rendering to wait for a promise with everything that I have tried.
So I figured out how to get the resource promise result to render server side. Just wrap the display of the result in a < Suspense>
tag.
Now I can finally have async wherever I want on the server side!
In setting up for SolidStarts next Beta Phase built on Nitro and Vinxi we are closing all PRs/Issues that will not be merged due to the system changing. If you feel your issue was closed by mistake. Feel free to re-open it after updating/testing against 0.4.x release. Thank you for your patience. See https://github.com/solidjs/solid-start/pull/1139 for more details.
Exporting a
routeData
function fromroot.tsx
doesn't seem to do anything. The function is not called under any circumstances.It seems like this has been mentioned on Discord already, but I'm opening this as a bug just to make sure the issue doesn't get lost. :sweat_smile: