Comments (7)
@gbj when trying to reproduce this in #2321 (comment), did you disable JS?
Edit: obviously you did. Otherwise you wouldn't have the query in the address bar.
from leptos.
Screen.Recording.2024-02-17.at.9.35.53.AM.mov
from leptos.
Oh, I see. Your example doesn't use the <Router>
.
The coordination between the error value stored in the route and the error value stored in the server action is handled by the router. I had the example wrapped in a <Router>
because I was pasting it into one of my usual templates.
from leptos.
Indeed, in my small example, it didn't work because the Router is missing. But my actual application uses a Router.
It seems it also doesn't work when using a custom error type (Here: String
):
use leptos::*;
use leptos_meta::*;
use leptos_router::*;
#[component]
pub fn App() -> impl IntoView {
provide_meta_context();
view! {
<Router>
<Routes>
<Route path="" view=Component/>
</Routes>
</Router>
}
}
#[component]
pub fn Component() -> impl IntoView {
let action = create_server_action::<Identity>();
let value = action.value();
view! {
<ActionForm action>
<input type="text" name="x"/>
<button type="submit">Submit</button>
</ActionForm>
{move || format!("{:?}", value.get())}
}
}
#[server(Identity)]
async fn identity(x: String) -> Result<String, ServerFnError<String>> {
Err(ServerFnError::from(x))
}
from leptos.
Indeed, in my small example, it didn't work because the Router is missing. But my actual application uses a Router.
It seems it also doesn't work when using a custom error type (Here: String):
Could you clarify: is your actual application using a custom error type, or does "also" here mean this is an additional bug?
from leptos.
This error handling setup is not currently implemented for custom error types.
When a server action is created, it looks for ServerFnUrlError
in context
leptos/leptos_server/src/action.rs
Lines 317 to 324 in ffcf3c2
It does not look directly at the URL, because the leptos_server
crate this is defined in isn't aware of things like URLs and routing — it does not even have a dependency on web-sys
or wasm-bindgen
, and is agnostic of whether it's in a browser environment or not. (Server functions can be used outside the browser.)
The ServerFnUrlError
is only provided for errors of type ServerFnError
, because when the router is checking for errors there's no way of telling it which custom error type that might be that's appeared in the URL:
leptos/router/src/components/router.rs
Lines 81 to 89 in ffcf3c2
I guess the alternative here would be to have the router just provide the __path
and __err
fields directly via context, and let every server action on the page try to decode them to its proper type, if it matches the path. That is probably a better implementation, in fact.
These two features (custom error types and no-JS ActionForm error handling) were introduced separately in 0.6 so the combination just fell through the cracks.
from leptos.
is your actual application using a custom error type, or does "also" here mean this is an additional bug?
My application uses a custom error type.
from leptos.
Related Issues (20)
- [0.7-beta5] Islands hydration issue (unique ID problem) HOT 3
- Double navigation cause desync beetween `Location::pathname` and the actual URL HOT 1
- [0.7] initial state of signal not read for dynamic classes HOT 2
- [0.7] Resource lacks `Debug`
- Compilation failed due to server_fn, no method found HOT 2
- Issues with runtime crashes when using ProtectedParentRoute HOT 5
- [0.7] panick when loading a blocking resource
- Nested routes in separate component don't compile when already inside ParentRoute. HOT 1
- Changes added in commit #5af7b54c seems to be causing issues with rendering svg icons
- Upgrade Lepros rkyv integration to support rkyv 8 HOT 1
- template macro page shows view macro page content HOT 1
- [0.7] runtime error: stored children already disposed HOT 1
- `expect_context` in server fn backing a resource panics when the resource is in a context HOT 2
- [0.7] `expect_context` not seeing the context within a router and a `<Show fallback>`
- leptos_macro: consider remove proc-macro-error as unmaintained HOT 2
- SVG elements don't show under certain conditions. HOT 1
- Context is lost across a `Suspend` boundary. HOT 6
- Reverse proxy on a subfolder breaks hydration HOT 7
- Using multiple `class` props on elements causes the last class props overwrite other classes
- External meta <Script/>: could not convert current node into marker node
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 leptos.