S
SolidJS13mo ago
zimo

call `createServerData$` outside Route?

Can I call createServerData$ outside of a Route? I want to put it in a header that is outside of my routes. Do I need to create a "master route" that has children?
2 Replies
thetarnav
thetarnav13mo ago
I think that createServerData$ is routeData + useRouteData + createResource + server$ Why not use just use createResource + server$? if you want to call it in root, you don't get any code-splitting benefit of routeData ah nvm, it's a wrapper around createRouteData, not routeData but does it really have a limitation that is has to be called in a route?
zimo
zimo13mo ago
hey thanks @thetarnav I'm pretty new to Solid Start so I actually didn't even know about the standalone server$... I'm using the auth.js example
const Header = () => {
const session = createServerData$(async (_, event) => {
return await getSession(event.request, authOptions);
});

return <Show when={session()} ...
};
const Header = () => {
const session = createServerData$(async (_, event) => {
return await getSession(event.request, authOptions);
});

return <Show when={session()} ...
};
I'm trying to rewrite it with only createResource + server$:
const [session] = createResource(server$(async (_, event) => {
return await getSession(event.request, authOptions);
}))
const [session] = createResource(server$(async (_, event) => {
return await getSession(event.request, authOptions);
}))
Normally it seems like createResource should take an async function so I'm not 100% sure if I did this right. Huh, actually the original
const session = createServerData$(async (_, event) => {
return await getSession(event.request, authOptions);
});
const session = createServerData$(async (_, event) => {
return await getSession(event.request, authOptions);
});
worked. I just accidentally had my header inside the routes instead of outside:
<ErrorBoundary>
<Routes>
<Header />
<FileRoutes />
</Routes>
</ErrorBoundary>
<ErrorBoundary>
<Routes>
<Header />
<FileRoutes />
</Routes>
</ErrorBoundary>
<ErrorBoundary>
<Header />
<Routes>
<FileRoutes />
</Routes>
</ErrorBoundary>
<ErrorBoundary>
<Header />
<Routes>
<FileRoutes />
</Routes>
</ErrorBoundary>
I'm still a bit curious how the createResource + server$ would work
Want results from more Discord servers?
Add your server
More Posts
`solid-start` site opens multiple `about:blank` on LoadMy `solid-start` page is opening multiple `about:blank` tabs when loading `localhost:3000` . Is theHow to keep/reuse DOM elements across routes?So, when using `solid-start` with routes, what is the most idiosyncratic way of keeping one element Disabling transition on load?I have a sticky navbar lower in the page which uses an intersection observer to transition to anothesetStore function replace object valuehttps://playground.solidjs.com/anonymous/f0b1602b-24a8-48db-a37d-e60db6eb3f85 ```tsx function CounteSolit-start routing works for a bit after `run dev`, but then only shows 404. Why?After starting dev `npm run dev`, I get the overview: ``` ** ➜ Page Routes: ┌─ http://localhConditional fetching with createResourceHi! Alright, this might be a little bit silly but here's my problem: I have a context provider compoIs there a polyfills.ts for `solid-start`? Or is there a way of modyfing the produced `index.html` ?So, in the `aws amplify` framework there is a common bug, which all frameworks have to fix somehow: Pure client based page complaining about `window is not defined` in solid-start (No SSR needed)Back when I was just working with `solid.js` I could use `window` in my code just fine, for. pages tWhy does typescript not accept `text() && text().length === x` in solid-start?Is anyone aware why typescript complains about ```ts text() && text().length === 6 ``` in a projecUniversal renderer createElement isn't runningI'm working on a custom renderer and I can't get the createElement function to run. I'm not sure if