sabercoy
sabercoy
Explore posts from servers
SSolidJS
Created by sabercoy on 9/10/2024 in #support
How does Transition API and createAsync interact?
No description
7 replies
SSolidJS
Created by sabercoy on 6/22/2024 in #support
Returning Errors and not throwing
I am messing around with actions and useSubmission and I have seen Ryan and the docs mention it is best to return, not throw, Errors
Rather than throwing errors, it is recommended to return them from actions. This helps with the typing of submissions that would be used with useSubmission. This is important when handling progressive enhancement where no JavaScript is present in the client, so that errors can be used declaratively to render the updated page on the server.
Rather than throwing errors, it is recommended to return them from actions. This helps with the typing of submissions that would be used with useSubmission. This is important when handling progressive enhancement where no JavaScript is present in the client, so that errors can be used declaratively to render the updated page on the server.
I dont understand the "so that errors can be used declaratively to render the updated page on the server" part Isnt the use of actions in forms and useSubmission always on the client? How are we rendering and updated page on the server? Dont we look at the submission and change the page on the client accordingly? (granted this requires JS)
8 replies
SSolidJS
Created by sabercoy on 6/15/2024 in #support
ErrorBoundary reset() method
what is reset() supposed to do?
import { action, cache, createAsync, reload, useAction } from "@solidjs/router";
import { ErrorBoundary, Suspense } from "solid-js";

const getData = cache(async () => {
'use server'

await new Promise(res => setTimeout(res, 1000))

if (Math.random() > .5) throw 'OOPS'

return 'data'
}, 'data')

const mutateData = action(async () => {
'use server'

reload({ revalidate: getData.key })
})

export default function Home() {
const data = createAsync(() => getData())
const mutateDataAction = useAction(mutateData)

return (
<main>
<ErrorBoundary fallback={(error, reset) => {
console.log('inside fallback')
return <div onClick={reset}>Error...</div>
}}>
<Suspense fallback={<div>Loading...</div>}>
<div>{data()}</div>
</Suspense>
</ErrorBoundary>
<button onClick={mutateDataAction}>mutate data action</button>
</main>
);
}
import { action, cache, createAsync, reload, useAction } from "@solidjs/router";
import { ErrorBoundary, Suspense } from "solid-js";

const getData = cache(async () => {
'use server'

await new Promise(res => setTimeout(res, 1000))

if (Math.random() > .5) throw 'OOPS'

return 'data'
}, 'data')

const mutateData = action(async () => {
'use server'

reload({ revalidate: getData.key })
})

export default function Home() {
const data = createAsync(() => getData())
const mutateDataAction = useAction(mutateData)

return (
<main>
<ErrorBoundary fallback={(error, reset) => {
console.log('inside fallback')
return <div onClick={reset}>Error...</div>
}}>
<Suspense fallback={<div>Loading...</div>}>
<div>{data()}</div>
</Suspense>
</ErrorBoundary>
<button onClick={mutateDataAction}>mutate data action</button>
</main>
);
}
if you run this and getData() errors, it will be caught be ErrorBoundary and the fallback will be rendered if you click the mutateDataAction button until getData() errors again, there will be an uncaught error if you call the reset() method (onClick handler on the div) it just re-runs the fallback function the docs say The reset function will reset the error boundary and re-render the children. if you call reset() then have getData() error again, it will not be caught if you call reset() the children are not reran, the fallback is reran what is the intended usage of reset()? and how can I make it to where multiple subsequent calls to getData() are handled properly if errors occur?
1 replies
SSolidJS
Created by sabercoy on 6/4/2024 in #support
The combination of API routes and data loading functions
I have been trying out integrating my existing API routes with cache and action deploying to cloudflare. The goal is to have the benefit of 1) preloading route data 2) having an open API 3) and being able to easily log API accesses. The examples with SS seem to want you to utilize server functions which would not be an open API and (I dunno) how I would log properly If I call fetch to an API route inside cache with no use server then it can be called on either client or server I need cookies/credentials, so calling on client is good because the browser will pass them, but on server there is no credentials and CF errors I can utilize use server to make each call a server function that calls an API route, then extract the headers from the event and wire into the fetch to make it as close as possible as if I called the API route from the browser But this seems very non-ergonomic.. It seems as though deciding to use cache and action means not having a good time with API routes, and instead opting to using only server functions
52 replies
SSolidJS
Created by sabercoy on 5/23/2024 in #support
Can cache be manually set?
Say I have a export const getList = cache(...) and I access the list using createAsync in multiple places in the app If a user chooses to delete the entire list in some section of the app and the request succeeds, the expected result for the list is now to be empty To my understanding with the current model, the way to update the list to be empty would be to revalidate it, probably in an action, which would trigger another call to the server to get the new list (which is empty) but say I want to not go to the server to get the obvious empty-list result. Is there a way I can manually set the list to empty? I had thought I could use cache.set() to do this, but upon using it nothing seems to happen (at least reactively) I know it is frowned upon to want to manually mutate state in the UI and not re-ask the server, but I can think of a few scenarios where this is harmless and beneficial. basically, I am wondering if there is an equivalent mutate() function from createResource for createAsync
14 replies