Madaxen86
I get ERR_UNHANDLED_REJECTION
Got it.
You can not export actions and query from files with top level "use server", because they need to run on the client.
Move them to another file or place the "use server" directive at the top of the async functions.
8 replies
Handling 404 within existing catch-all route
Wrap the page also in a Suspense as data will be undefined until it has resolved. Otherwise you'll be showing your NotFound while fetching.
Alternatively. You can check in getPageData if the response has data and throw if not. Keeps your page cleaner.
5 replies
I get ERR_UNHANDLED_REJECTION
Can't reproduce it.
Maybe you can in a stackblitz?
https://stackblitz.com/edit/github-52ahab?file=src%2Froutes%2Findex.tsx,src%2Fserver.ts
What's your router version?
Unrelated: You'll probaly need to "use server" to the function to be able to get and update the session.
8 replies
Problems to acess objects inside an array
Have a look at this guide.
With
produce
you‘ll simplify your code.
https://docs.solidjs.com/guides/complex-state-management#adding-to-an-array6 replies
Handling <input>
Well not a controlled by React’s definition.
Because in Solid all elements are real HTML elements they will fallback to their native behavior. For an input value is then just the defaultValue in Reacts sense.
But you can control what's displayed on the input e.g. make all characters lowercase. That's controlled for me...
6 replies
Server Side Rendering
You can check if a component/ page is rendered on the server or client by placing a console log in the component.
If the log appears in the terminal it’s server rendered, if it’s in the browser console it’s client rendered.
There’s also the
isServer
helper you can import.
Solid-Start will be in SSR mode by default or you can like you did set SSR to true.
The app will then render on the server whenever a url is directly hit or when the browser is refreshed.
Once the app is hydrated on the client/browser solid will switch to client side routing and rendering.
Regarding createAsync and meta tags. Browsers don’t pick up when the title is changed, so using deferStream and you can also wrap the title in a Show
(I’m not sure if Suspense
does also work for meta tags ) component to make sure it will only be rendered once the async resource has resolved is correct. Because solid will start to stream chunk of the page to the client which are ready.4 replies
How to Implement Page Caching
If you are using solid-start then browser back will restore the scroll position by default.
With the
useBeforeLeave
helper you can check if the to
route is equal to the previous route. (You either need to implement the Memory router
or track the previous route yourself). And the prevent.default() the event and trigger the history.before() to restore the scroll position.
https://docs.solidjs.com/solid-router/reference/primitives/use-before-leave
Regading caching
. Currently the there's no caching mechanis besides the 5 seconds deduping "cache" of the query
wrapper function build into @solidjs/router
You might want to take a look at Tanstack query
which is great for dashboards. It'll has an api for caching which gives you total control.
https://tanstack.com/query/latest/docs/framework/solid/quick-start2 replies
Cache with sanity
In one of my projects I added this:
This will revalidate the cached function whenever a user revisits the page. So on desktop it would even fire when the user switches to another tab and comes back.
Of course this increases the traffic.
Have you set any caching headers?
Like
max-age
or Cache-Control: no-cache
16 replies
<Show> not tracking signals
I can’t really explain this.
It may be that Show does not realise that the reference to the map has changed!?
You can check solid primitive’s reactive map
https://primitives.solidjs.community/package/map#reactivemap
28 replies
Why does this loop infinitely
Tough to make a solid statement without seeing the code.
By default action revalidate the whole cache and this doesn’t create infinite loops.
Keep your createAsync outside of reactive contexts (jsx,createEffect,createMemo) and you will be fine.
6 replies
can I import a `named export` while lazy loading the `default export`?
Well if your app root imports a component. And the app root is used in any route. Then lazy loading the same component on a specific route does not reduce the base bundle.
But give it a try and check the bundle. Then you know for sure.
4 replies