You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to set up a URL-param-driven protected page, but it seems like protected$ is rewriting working code into not-working code. Specifically, I have a createAsync call that depends on a value in the local scope (the params) but when protected$ rewrites that code, that call gets hoisted to a different scope in which the params don't exist, causing a runtime error.
I'm fairly new to SolidStart, am I approaching this wrong, or is this a bug?
Route with optional parameter: events/[[page]].tsx
As you can see, events depends on the page memo, which depends on params.
Same code, as rewritten by protected$ gets a page is not defined error, because page is now in a different scope from the code that depends on it. Is there a different way for my createAsync code to reference URL parameters that I should be using?
import{authOptions}from"~/lib/server/auth";import{Show}from"solid-js";import{getSession}from"@solid-mediakit/auth";import{getRequestEvent}from"solid-js/web";import{protected$}from'@solid-mediakit/auth';import{Title}from'@solidjs/meta';import{createAsync,query,useParams}from'@solidjs/router';import{For,Suspense,createMemo}from'solid-js';import{events}from'~/lib/server/db';const_$$getUser=query(async()=>{'use server';constevent=getRequestEvent();constsession=awaitgetSession(event.request,authOptions);if(!session){throwredirect("/login");}returnsession;},"media-user");constgetEvents=query(asyncpage=>{'use server';returnawaitevents.getRecentEvents(page,10);},'events');exportconstroute={preload: ()=>getEvents()};exportdefault()=>{constevents=createAsync(()=>getEvents(page()));// <-- not here!const_$$session=createAsync(()=>_$$getUser(),{deferStream: true});const_$$RenderProtected=()=>{constparams=useParams();constpage=createMemo(()=>{constparsed=Number.parseInt(params.page);if(Number.isNaN(parsed)){return0;}returnparsed;});// <-- should be herereturn(...);};return<Showwhen={_$$session()?.user}><_$$RenderProtected/></Show>;};
The text was updated successfully, but these errors were encountered:
I'm trying to set up a URL-param-driven protected page, but it seems like
protected$
is rewriting working code into not-working code. Specifically, I have acreateAsync
call that depends on a value in the local scope (the params) but whenprotected$
rewrites that code, that call gets hoisted to a different scope in which the params don't exist, causing a runtime error.I'm fairly new to SolidStart, am I approaching this wrong, or is this a bug?
Route with optional parameter:
events/[[page]].tsx
Original version of that code:
As you can see,
events
depends on thepage
memo, which depends onparams
.Same code, as rewritten by
protected$
gets apage is not defined
error, becausepage
is now in a different scope from the code that depends on it. Is there a different way for mycreateAsync
code to reference URL parameters that I should be using?The text was updated successfully, but these errors were encountered: