solidjs / solid-start

SolidStart, the Solid app framework
https://start.solidjs.com
MIT License
5.18k stars 375 forks source link

`routeData` Is Not Called from the `root.tsx` File #647

Closed ITenthusiasm closed 10 months ago

ITenthusiasm commented 1 year ago

Exporting a routeData function from root.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:

ryansolid commented 1 year 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.

benoitv-code commented 1 year ago

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)

cjdell commented 1 year ago

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.

hardywu commented 1 year ago

@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.

cjdell commented 1 year ago

@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.

cjdell commented 1 year ago

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!

ryansolid commented 10 months ago

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.