Comments (9)
Throwing the redirect also works, but the important part is calling loadData
outside of the load
function, since thrown/returned redirects will be ignored when called from load
.
https://stackblitz.com/edit/github-fk8exj-mcht9p?file=src%2Froutes%2Findex.tsx
from solid-start.
I feel this is intended behavior at the moment. Thinking we can probably close this issue?
from solid-start.
So a couple things you need to do. You need to return instead of throw the redirect. Secondly you need to wrap in the cache function. Also you need to call the function in createAsync()
const loadData = cache(() => {
'use server'
return redirect('/about')
}, "load-data");
export const route = {
load: () => loadData()
}
export default function Home() {
const data = createAsync(() => loadData());
}
from solid-start.
What if I don't want to cache the request? For example, if I want to validate some auth-link with some hash parameter, and then want to redirect user. I don't think I want to cache the response in this case.
from solid-start.
Use action
, it's for pretty much everything that isn't a data fetch
from solid-start.
Can I use action
on page load? The use-case I'm trying to solve is:
- I send email to the user with a unique link
- User clicks the link and is taken to the link validation page
- I validate link on the server
- If validation is successful, I redirect the user
- If validation is not successful, I want to show some error state with some next action, so user is not lost.
I also, don't want to cash that response, so if link is clicked twice, it is no longer valid
from solid-start.
Yeah that should work fine
from solid-start.
So should it be like this:
const loadData = action(() => {
'use server'
return redirect('/about')
});
export const route = {
load: () => loadData()
}
export default function Home() {
const data = createAsync(() => loadData());
}
from solid-start.
Yeah this is by design since the load
function is more of like a lifecycle hook and the server function is just an async function. One could catch the errored response themselves and then call the client side navigation APIs with it but I don't know if that is what you are going for. The name cache
is probably misleading because on the server it only lasts the lifetime of the request. It is possible it would just work. We're reviewing some of the naming.
I think an action is fine, but I think cache
more fits the semantics because it is getting is validated on a hash. But either probably is fine here.
from solid-start.
Related Issues (20)
- [Bug?]: Cannot get response returned by a server function via a GET request HOT 1
- [Bug?]:TypeError: Cannot read properties of null (reading 'FormContext')
- [Bug?]: [vite] Pre-transform error: xxx.tsx: Property value expected type of boolean but got undefined HOT 1
- [Bug?]: Server action chunks are not generated in production build when using `experimental.islands` HOT 5
- [Feature?]: Websocket for SolidStart/SolidJS, instead of fetch HOT 2
- Issue with File Updates on Dev Server HOT 1
- [Feature?]: Tailwind template should come with automatic theme switching support "out-of-the-box"
- [Bug?]: Hydration Mismatch for passed JSX elements HOT 5
- [Bug?]: `compressPublicAssets` nitro config does not work HOT 4
- [Bug?]: Wrong server function called due to incorrect handling of file hash collisions for server func sources
- [Bug?]: Landing page is broken on small screen size
- [Bug?]: how to prerender *404 page? HOT 2
- [Feature?]: Add an option to disable lazy loading in `<FileRoutes />` HOT 3
- [Bug?]: "Zero-config" Netlify provider does not load a Netlify preset automatically HOT 4
- [Bug?]: TypeError: Response body object should not be disturbed or locked HOT 3
- [Bug?]: pnpm create solid@latest doesn't work HOT 1
- [Bug?]: Using layouts with route groups at root level causes hydration errors HOT 3
- [Bug?]: Unexpected Link Element Generation for Stylesheet Imports in Production Environment HOT 1
- API routes have to be inline exported function declarations
- [Feature?]: Add ability to add/modify head classes, lang and lang dir HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from solid-start.