Silverdagger
Silverdagger
Explore posts from servers
SSolidJS
Created by Silverdagger on 9/1/2023 in #support
Any pattern to avoid getting ts angry when using route data fields?
Alas TS is appeased 😄 thanks. Didn't know you could throw the redirect
20 replies
SSolidJS
Created by Silverdagger on 9/1/2023 in #support
Any pattern to avoid getting ts angry when using route data fields?
export function routeData() {
return createServerData$(async (_, { request }) => {
const user = await getUser(request)
if (user === null) return redirect('/login')
const clans = await prisma.clanmember.findMany({
select: {
clan: { select: { id: true, clanname: true } },
accepted: true,
},
where: { userId: user.id },
})
return {
invitations: clans.filter((invite) => !invite.accepted),
member: clans.filter((member) => member.accepted),
}
})
}
export function routeData() {
return createServerData$(async (_, { request }) => {
const user = await getUser(request)
if (user === null) return redirect('/login')
const clans = await prisma.clanmember.findMany({
select: {
clan: { select: { id: true, clanname: true } },
accepted: true,
},
where: { userId: user.id },
})
return {
invitations: clans.filter((invite) => !invite.accepted),
member: clans.filter((member) => member.accepted),
}
})
}
20 replies
SSolidJS
Created by Silverdagger on 9/1/2023 in #support
Any pattern to avoid getting ts angry when using route data fields?
No description
20 replies
SSolidJS
Created by Silverdagger on 9/1/2023 in #support
Any pattern to avoid getting ts angry when using route data fields?
I accidentally sent the wrong image While I was attempting various ways to fix it - so I changed it later sorry for that
20 replies
SSolidJS
Created by Silverdagger on 8/31/2023 in #support
Missing Http method returns 200 status code on api route
not sure what you mean
20 replies
SSolidJS
Created by Silverdagger on 8/31/2023 in #support
Missing Http method returns 200 status code on api route
routes/api/endpoint.ts
20 replies
SSolidJS
Created by Silverdagger on 8/31/2023 in #support
Missing Http method returns 200 status code on api route
yeah this is what I do atm -> create catch all routes and return 405 on all of them myself -> Just thought that maybe I missed something to "enable" this feature to do it for any undefined routes
20 replies
SSolidJS
Created by Silverdagger on 8/31/2023 in #support
Missing Http method returns 200 status code on api route
No description
20 replies
SSolidJS
Created by Silverdagger on 8/29/2023 in #support
How can I populate HTML on the server with db data before sending it to the client
Alright I see - so it's fine as it is now - Thanks a lot for taking the time to explain & walk me through this
38 replies
SSolidJS
Created by Silverdagger on 8/29/2023 in #support
How can I populate HTML on the server with db data before sending it to the client
Ok so basically me changing into what I want will basically have no real effect since it fetches both document and data at the same time and instead of merging them at the server it does so in the client right?
38 replies
SSolidJS
Created by Silverdagger on 8/29/2023 in #support
How can I populate HTML on the server with db data before sending it to the client
No description
38 replies
SSolidJS
Created by Silverdagger on 8/29/2023 in #support
How can I populate HTML on the server with db data before sending it to the client
You are correct - I falsely assumed you were getting back a document on each route.. So essentially the server sends the entire app on the initial load and then the client takes over (working as a CSR from then on?)
38 replies
SSolidJS
Created by Silverdagger on 8/29/2023 in #support
How can I populate HTML on the server with db data before sending it to the client
Alright I made a bit of progress thanks to your input. The behaviour is as you described (if i navigate directly to /profile I get the page without any additional request made which is what i want ) but the data still gets fetched via post if I navigate to the same /profile route using a link. To be more specific, if i navigate using <a> it works as expected but page fully reloads , on the other hand using <A> a post request is sent Is there a way to specify that I need the data only as html and resolve all resources before sending it to the client? I paste my code below if it helps (maybe I did something different than what you described)
import ClientProfilePage from '~/components/clientprofilepage'
import { ProfileContextProvider } from '~/components/profileprovider'
import { prisma } from '~/lib/prismaclient'
import {
ErrorBoundary,
RouteDataArgs,
useNavigate,
useRouteData,
} from 'solid-start'
import { createServerData$, redirect } from 'solid-start/server'
import { Show } from 'solid-js'
import { getUser } from '~/lib/sessions'

export function routeData({ params }: RouteDataArgs) {
return createServerData$(async (_, { request }) => {
const user = await getUser(request)
if (user === null) return redirect('/login')
const profile = await prisma.user.findUnique({
select: { id: true, username: true, email: true, createdAt: true },
where: { id: user!.id },
})

if (!profile) {
return redirect('/login')
}
return profile
})
}

export default function MyProfile() {
const navigate = useNavigate()
console.log('myprofile called')
const profile = useRouteData()

return (
<div class="max-w-screen-xl mx-auto">
<ErrorBoundary>
<Show when={profile() && !profile.loading} fallback={'Waiting...'}>
<ProfileContextProvider profile={profile()}>
<ClientProfilePage />
</ProfileContextProvider>
</Show>
</ErrorBoundary>
</div>
)
}
import ClientProfilePage from '~/components/clientprofilepage'
import { ProfileContextProvider } from '~/components/profileprovider'
import { prisma } from '~/lib/prismaclient'
import {
ErrorBoundary,
RouteDataArgs,
useNavigate,
useRouteData,
} from 'solid-start'
import { createServerData$, redirect } from 'solid-start/server'
import { Show } from 'solid-js'
import { getUser } from '~/lib/sessions'

export function routeData({ params }: RouteDataArgs) {
return createServerData$(async (_, { request }) => {
const user = await getUser(request)
if (user === null) return redirect('/login')
const profile = await prisma.user.findUnique({
select: { id: true, username: true, email: true, createdAt: true },
where: { id: user!.id },
})

if (!profile) {
return redirect('/login')
}
return profile
})
}

export default function MyProfile() {
const navigate = useNavigate()
console.log('myprofile called')
const profile = useRouteData()

return (
<div class="max-w-screen-xl mx-auto">
<ErrorBoundary>
<Show when={profile() && !profile.loading} fallback={'Waiting...'}>
<ProfileContextProvider profile={profile()}>
<ClientProfilePage />
</ProfileContextProvider>
</Show>
</ErrorBoundary>
</div>
)
}
38 replies
SSolidJS
Created by Silverdagger on 8/29/2023 in #support
How can I populate HTML on the server with db data before sending it to the client
It seems like such a simple task I am ashamed to admit I can't figure out how to make it work
38 replies
SSolidJS
Created by Silverdagger on 8/29/2023 in #support
How can I populate HTML on the server with db data before sending it to the client
I selected SSR in the initialization options (althought it doesn't state anything about it in the vite config i believe that it is because its true by default) -> the server$ from what I saw does a post request fetching the data and I want to avoid having extra requests when the data doesn't require reactivity
38 replies
SSolidJS
Created by Silverdagger on 8/29/2023 in #support
How can I populate HTML on the server with db data before sending it to the client
It matches the usecase of the app I am trying to port from NextJS (one call to fetch the html instead of 2 for html+data)
38 replies
SSolidJS
Created by Silverdagger on 8/29/2023 in #support
How can I populate HTML on the server with db data before sending it to the client
This does a post request to fetch the data, I need the data to render on the server and be sent as html.
38 replies
SSolidJS
Created by Silverdagger on 8/29/2023 in #support
How can I populate HTML on the server with db data before sending it to the client
If I don't use the 'isServer' the code executes in both client and server which is not the behavior I need. I want to query the db - build the page and ship it as html. How can I achieve this?
38 replies
SSolidJS
Created by Zanoryt on 8/12/2023 in #support
Now using createResource(), the content never loads.
sure my problem is explained here - any help would be appreciated since i am new with solid in general https://discord.com/channels/722131463138705510/1145875082074407004
11 replies