DioxusLabs / DioxusLabs/dioxus

Context is not provided to event handlers in inline component children

Open
#4,015 2 comments 0 reactions 0 assignees View on GitHub
bug core
Dominant language
Rust
Stars
39.1k
Forks
1.9k
Avg merge
4d 10h
Merged PRs (30d)
4

Description

**Problem**

This is a spin-off from #4011

The `ErrorBoundary` construction seems entirely broken.

**Steps To Reproduce**

```rust
use dioxus::prelude::*;

const FAVICON: Asset = asset!("/assets/favicon.ico");
const MAIN_CSS: Asset = asset!("/assets/main.css");

fn main() {
dioxus::launch(App);
}

#[component]
fn App() -> Element {
rsx! {
document::Link { rel: "icon", href: FAVICON }
document::Link { rel: "stylesheet", href: MAIN_CSS }
Hero {}
}
}

#[component]
pub fn TryToCatchError(title: String) -> Element {
rsx! {
ErrorBoundary {
handle_error: |_| {
// We would expect to see this (we do not)
rsx! { "WORKS" }
},
button {
// Simulate some kind of failure happening
onclick: move |_| {
Err(std::io::Error::new(std::io::ErrorKind::Other, "oh no!"))?;
Ok(())
},

"{title}"
}
}
}
}

#[component]
pub fn Hero() -> Element {
rsx! {
div {
id: "hero",
// case 1: This should work, I think?
TryToCatchError { title: "This explodes" }

// case 2: This "works", but catches the error at the wrong (outer) boundary
ErrorBoundary {
handle_error: |_| {
// We would NOT expect to see this (but we do)
rsx! { "FAILED" }
},

TryToCatchError { title: "This fails" }
}
}
}
}
```

**Expected behavior**

In both cases, I would expect `TryToCatchError` to catch the error internally, but this never happens.

In the first case, the error bubbles all the way out, replacing the view of our app with a full-screen error message (and no backtrace, for some reason?)

In the second case, the *outer* `ErrorBoundary` does seem to catch the error, but never the inner one.

**Environment:**

- Dioxus version: `dioxus = { version = "0.6.0", features = [] }`
- Rust version: `rustc 1.85.0 (4d91de4e4 2025-02-17)`
- OS info: `Debian Stable (12.10)`
- App platform: `web`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.