S
SolidJS13mo ago
Metru

I'm having trouble with `session.data` being undefined

Starting from the with-auth example, user_id is sometimes undefined when e.g. refreshing the page.
const session = await getSession()
const user_id = session.data.user_id

console.log({ user_id });
const session = await getSession()
const user_id = session.data.user_id

console.log({ user_id });
I've made a minimal reproduction of the issue here: https://github.com/metruzanca/solidstart-getSession-bug-repro First commit is the initted project, second is the code that's causing the issue. I've also got a video showing off the problem.
19 Replies
Metru
MetruOP13mo ago
Video reproduction / explanation of the setup (also included in the repo)
Metru
MetruOP12mo ago
This issue also works in production
bigmistqke
bigmistqke12mo ago
there has been other accounts of weird stuff happening with context: https://discord.com/channels/722131463138705510/1189503397091606548 maybe good to add an issue in the solid start gh repo, or add a comment here https://github.com/solidjs/solid-start/issues/1185
GitHub
[Bug?]: Issue with context who don't return the value · Issue #1185...
Duplicates I have searched the existing issues Latest version I have tested the latest version Current behavior 😯 Hello I have a very strange bug with the new solid-start template : I have a librar...
Metru
MetruOP12mo ago
Already made an issue yesterday actually https://github.com/solidjs/solid-start/issues/1192
GitHub
[Bug?]: useSession().data value inconsistent · Issue #1192 · soli...
Duplicates I have searched the existing issues Latest version I have tested the latest version Current behavior 😯 Sometimes session.data.userId is undefined when expected to be defined. Expected be...
Metru
MetruOP12mo ago
I'll take a look, maybe comment + reference
bigmistqke
bigmistqke12mo ago
nice
Metru
MetruOP12mo ago
really wanna get this working so I can keep using solidstart 😅
bigmistqke
bigmistqke12mo ago
ye, was to be expected some new bugs would arise from the new beta. thanks for leading the way and finding them!
Metru
MetruOP12mo ago
I just wasn't expecting the first but I run into to be this.. road blocking. beta1 was buggy but it was all negligible stuff Actually beta1 was quite stable
bigmistqke
bigmistqke12mo ago
it got quite stable but it wasn't from the start
Metru
MetruOP12mo ago
I did have to do the good old make new projecte and copy over files into existing project to update version, thing once but aside from that, beta1 treated me well. Though, can't say I've used a lot of the server$ features. I'm using them a lot more now Anyways, thanks for taking the time.
bigmistqke
bigmistqke12mo ago
r u trying to access the context inside the server-function? ye ur welcome 👍 sadly can't help too much. can only repeat what i have seen passing by recently because it was only when refreshing the page right? i wonder if it's something like: during client navigation it happens inside the client and context is available, but when refreshing the page it goes to the server and there it isn't?
Metru
MetruOP12mo ago
In theory, the function is in a "use server" file, so it should only ever run on the server afaik yeah, I need the session.data.userId, but I can't determine why its undefined sometimes when visiting the page Even in production its got this behaviour
bigmistqke
bigmistqke12mo ago
mm, i remember alexis saying something about accessing context in a server-function @lxsmnsyc 🤖 does this ring a bell?
lxsmnsyc
lxsmnsyc12mo ago
it's a getRequestEvent so it should work
Metru
MetruOP12mo ago
@bigmistqke Absolutely wanted to keep using solidjs (after briefly moving to astrojs and already missing the form actions DX) managed to find a workaround. https://github.com/metruzanca/solidstart-getSession-bug-repro/commit/17630999eb7db501defebe3fd801aa7db83f6c30 It does need some error checking though!
bigmistqke
bigmistqke12mo ago
nice work, that will be helpful in finding the root cause.
Metru
MetruOP12mo ago
Like, if session doesn't exist, process.exit()'s Gonna find a good way to check that then add that to the workaround Easy enough, just add some good old try catch and don't assert not falsey for cookie xD https://github.com/metruzanca/solidstart-getSession-bug-repro/commit/ed2020900b44202ad3bbe8f6b310946c3e6cb52a But yeah, this works now and is probably good enough to keep going until Jan 1st when the solid team gets back from holidays.
Want results from more Discord servers?
Add your server