Ping for toast
Ping for toast
Explore posts from servers
SSolidJS
Created by Ping for toast on 8/9/2024 in #support
Infinite context loop in start dev?
Hi, I have
const [MeProvider, useMe] = createContextProvider(() => {
let [me, { mutate: setMe, refetch: refreshMe }] = createResource(async () => {
// this runs forever
console.log("running!")
return (await client.user.me.get()).data;
});
return {
me,
setMe,
refreshMe,
};
});
const [MeProvider, useMe] = createContextProvider(() => {
let [me, { mutate: setMe, refetch: refreshMe }] = createResource(async () => {
// this runs forever
console.log("running!")
return (await client.user.me.get()).data;
});
return {
me,
setMe,
refreshMe,
};
});
, and I'm noticing that this createResource is running forever as fast as possible, on the server, when its in dev. I'm trying to discover the root cause of it, but it only happens in dev. I'm posting this half for help, and half to help others when I uncover the issue
15 replies
SSolidJS
Created by Ping for toast on 1/8/2023 in #support
Await Resource
I have an authentication context wrapping the router
export const [SessionProvider, useSession] = createContextProvider(() => {
const cookie = isServer
? useRequest().request.headers.get("cookie") ?? ""
: document.cookie
const [userSession] = createResource(async () => {
const session = await storage.getSession(cookie)
return {
instance: session.get('instance') as string || null,
key: session.get('key') as string || null
}
}, {
deferStream: true
})
return userSession
})
export const [SessionProvider, useSession] = createContextProvider(() => {
const cookie = isServer
? useRequest().request.headers.get("cookie") ?? ""
: document.cookie
const [userSession] = createResource(async () => {
const session = await storage.getSession(cookie)
return {
instance: session.get('instance') as string || null,
key: session.get('key') as string || null
}
}, {
deferStream: true
})
return userSession
})
And later use the session context in certain functions
const gclc = () => createClient({
url: `https://${useSession()().instance}/api/graphql`,
fetchOptions: () => {
return {
headers: {
'Authorization': `Bearer ${useSession()().key}`
}
}
}
})
const gclc = () => createClient({
url: `https://${useSession()().instance}/api/graphql`,
fetchOptions: () => {
return {
headers: {
'Authorization': `Bearer ${useSession()().key}`
}
}
}
})
But it appears that in some contexts, useSession is still unloaded when it is called. I need some way to await the resource ready state if it isn't ready already, or some better way to do this
2 replies