Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suspense boundaries/out of order streaming/anyhow like error handling #2365

Merged
merged 227 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
227 commits
Select commit Hold shift + click to select a range
2d3c9d9
create static site generation helpers in the router crate
ealmloff Apr 2, 2024
6d3383b
work on integrating static site generation into fullstack
ealmloff Apr 2, 2024
8524cb4
move ssg into a separate crate
ealmloff Apr 2, 2024
9045a83
integrate ssg with the launch builder
ealmloff Apr 2, 2024
e6b7f60
simplify ssg example
ealmloff Apr 2, 2024
033a8ce
fix static_routes for child routes
ealmloff Apr 3, 2024
a87c84c
Merge branch 'main' into ssg-platform
ealmloff Apr 5, 2024
51d5037
move CLI hot reloading websocket code into dioxus-hot-reload
ealmloff Apr 8, 2024
8f57cd2
fix some unused imports
ealmloff Apr 8, 2024
07651fc
use the same hot reloading websocket code for fullstack
ealmloff Apr 8, 2024
6111440
fix fullstack hot reloading
ealmloff Apr 8, 2024
2261abf
move cli hot reloading logic into the hot reload crate
ealmloff Apr 8, 2024
0e332b9
ssg example working with dx serve
ealmloff Apr 9, 2024
d8959b9
add more examples
ealmloff Apr 9, 2024
870af43
Merge branch 'main' into ssg-platform
ealmloff Apr 9, 2024
0290b8d
fix clippy
ealmloff Apr 9, 2024
ca06678
switch to a result for Element
ealmloff Apr 24, 2024
ab4b59c
Merge branch 'main' into ssg-platform
ealmloff May 1, 2024
2d831d3
fix formatting
ealmloff May 1, 2024
6ea9cca
fix hot reload doctest imports
ealmloff May 1, 2024
b306c22
fix axum imports
ealmloff May 1, 2024
64ad951
add show method to error context
ealmloff May 11, 2024
adbca5e
implement retaining nodes during suspense
ealmloff May 14, 2024
5c65347
fix unterminated if statements
ealmloff May 14, 2024
9e9d5d8
communicate between tasks and suspense boundaries
ealmloff May 14, 2024
d8ed8ca
make suspense placeholders easier to use
ealmloff May 14, 2024
ef42f0b
implement IntoDynNode and IntoVNode for more wrappers
ealmloff May 14, 2024
0255573
fix clippy examples
ealmloff May 14, 2024
4c87aa6
fix rsx tests
ealmloff May 15, 2024
f6ef62b
add streaming html utilities to the ssr package
ealmloff May 20, 2024
7fe3d4d
unify hydration and non-hydration ssr cache
ealmloff May 20, 2024
629daae
fix router with Result Element
ealmloff May 20, 2024
34355ad
don't run server doc tests
ealmloff May 20, 2024
2969e93
Merge branch 'main' into ssg-platform
ealmloff May 20, 2024
ac76705
Fix hot reload websocket doc examples
ealmloff May 20, 2024
88b7014
simple apps working with fullstack streaming
ealmloff May 20, 2024
0e15706
fix preloading wasm
ealmloff May 20, 2024
cef7835
Merge branch 'main' into suspense-2.0
ealmloff May 20, 2024
538f676
Report errors encountered while streaming
ealmloff May 20, 2024
0bdcd20
Merge branch 'ssg-platform' into suspense-2.0
ealmloff May 20, 2024
229f139
Merge branch 'main' into suspense-2.0
ealmloff May 20, 2024
0c26758
remove async from incremental renderer
ealmloff May 21, 2024
d0d6a69
document new VirtualDom suspense methods
ealmloff May 21, 2024
40e9432
make streaming work with incremental rendering
ealmloff May 21, 2024
348370e
fix static site generation
ealmloff May 21, 2024
a538278
document suspense structs
ealmloff May 21, 2024
b4e07d1
create closure type; allow async event handlers in props; allow short…
ealmloff May 22, 2024
f3ee653
test forwarding event handlers with the shorthand syntax
ealmloff May 22, 2024
40fd457
fix clippy
ealmloff May 22, 2024
ff9ac66
fix imports in spawn async doctest
ealmloff May 22, 2024
a810cd6
fix empty rsx
ealmloff May 22, 2024
4527e6c
Merge branch 'closures' into suspense-2.0
ealmloff May 22, 2024
fb68e83
fix async result event handlers
ealmloff May 22, 2024
8400ef6
fix mounting router in multiple places
ealmloff May 22, 2024
3aa3b05
Fix task dead cancel race condition
ealmloff May 23, 2024
88f09c2
simplify diffing before adding suspense
ealmloff May 24, 2024
27e876b
fix binary size increase
ealmloff May 24, 2024
a9dd8d3
fix attribute diffing
ealmloff May 24, 2024
9faa35c
more diffing fixes
ealmloff May 24, 2024
4a1b015
create minimal fullstack feature
ealmloff May 24, 2024
2f31855
smaller fullstack bundles
ealmloff May 27, 2024
94e5821
allow mounting nodes that are already created and creating nodes with…
ealmloff May 27, 2024
cacd8ec
fix hot reload feature
ealmloff May 27, 2024
3a3149e
fix replacing components
ealmloff May 27, 2024
03947f4
don't reclaim virtual nodes
ealmloff May 27, 2024
da98835
client side suspense working!
ealmloff May 28, 2024
cdd3977
fix CLI
ealmloff May 28, 2024
e0c4e22
slightly smaller fullstack builds
ealmloff May 28, 2024
4c3fbc7
fix multiple suspended scopes
ealmloff May 29, 2024
fbb2fb0
Merge branch 'fix-task-race-condition' into suspense-2.0
ealmloff May 29, 2024
5dcc2d0
fix merge errors
ealmloff May 29, 2024
7e88f22
yield back to tokio every few polls to fix suspending on many tasks a…
ealmloff May 30, 2024
1266223
remove logs
ealmloff May 30, 2024
36e9f87
document suspense boundary and update suspense example
ealmloff Jun 3, 2024
64987fe
fix ssg
ealmloff Jun 3, 2024
90c20ba
make streaming optional
ealmloff Jun 3, 2024
14504f1
fix some router and core tests
ealmloff Jun 3, 2024
9cc00e8
fix suspense example
ealmloff Jun 4, 2024
db5eb56
fix serialization with out of order server futures
ealmloff Jun 4, 2024
f24b672
add incremental streaming hackernews demo
ealmloff Jun 4, 2024
d79886a
fix hackernews demo
ealmloff Jun 4, 2024
dfdf18e
fix root hackernews redirect
ealmloff Jun 4, 2024
f7fe838
fix formatting
ealmloff Jun 4, 2024
3a64027
add tests for suspense cases
ealmloff Jun 5, 2024
569c303
slightly smaller binaries
ealmloff Jun 5, 2024
872ef99
slightly smaller
ealmloff Jun 5, 2024
58d4ff9
Merge branch 'main' into suspense-2.0
ealmloff Jun 5, 2024
cad3fe5
improve error handling docs
ealmloff Jun 5, 2024
11403f3
fix errors example link
ealmloff Jun 5, 2024
3e2ef47
fix doc tests
ealmloff Jun 6, 2024
f578723
remove log file
ealmloff Jun 6, 2024
5f4626d
fix ssr cache type inference
ealmloff Jun 6, 2024
94d0ace
remove index.html
ealmloff Jun 6, 2024
ab1d474
fix ssg render template
ealmloff Jun 6, 2024
18cc74d
fix assigning ids on elements with dynamic attributes
ealmloff Jun 6, 2024
6830e8c
add desktop feature to the workspace examples
ealmloff Jun 6, 2024
8fb3111
remove router static generation example; ssg lives in the dioxus-stat…
ealmloff Jun 6, 2024
e632358
add a test for effects during suspense
ealmloff Jun 7, 2024
6064618
only run effects on mounted nodes
ealmloff Jun 10, 2024
6f1d0d5
fix multiple suspense roots
ealmloff Jun 10, 2024
c275dea
Merge branch 'main' into suspense-2.0
ealmloff Jun 10, 2024
d1d00e3
fix node iterator
ealmloff Jun 10, 2024
e9027e5
fix closures without arguments
ealmloff Jun 10, 2024
9a1c51b
fix dioxus-core readme doctest
ealmloff Jun 10, 2024
ae436ed
remove suspense logs
ealmloff Jun 10, 2024
9f770fa
fix scope stack
ealmloff Jun 10, 2024
8cada66
Merge branch 'main' into suspense-2.0
ealmloff Jun 12, 2024
dd60353
fix clippy
ealmloff Jun 12, 2024
31c87e5
remove unused suspense boundary from hackernews
ealmloff Jun 12, 2024
e950bd4
assert that launch never returns for better compiler errors
ealmloff Jun 13, 2024
20406e0
fix static generation launch function
ealmloff Jun 13, 2024
30c862a
fix web renderer
ealmloff Jun 14, 2024
e2b98c5
pass context providers into server functions
ealmloff Jun 13, 2024
5210a4b
add an example for FromContext
ealmloff Jun 13, 2024
0cc0712
clean up DioxusRouterExt
ealmloff Jun 13, 2024
261a14c
fix server function context
ealmloff Jun 13, 2024
b3beada
fix fullstack desktop example
ealmloff Jun 13, 2024
c937929
forward CLI serve settings to fullstack
ealmloff Jun 14, 2024
244e6b9
re-export serve config at the root of fullstack
ealmloff Jun 14, 2024
ee7fe8e
forward env directly instead of using a guard
ealmloff Jun 19, 2024
e4c2b70
just set the port in the CLI for fullstack playwright tests
ealmloff Jun 19, 2024
0961026
Merge branch 'main' into forward-cli-serve-settings
ealmloff Jun 19, 2024
ec5236b
fix fullstack dioxus-cli-config feature
ealmloff Jun 19, 2024
5c58607
fix launch server merge conflicts
ealmloff Jun 19, 2024
e150711
fix fullstack launch context
ealmloff Jun 19, 2024
a385c91
Merge branch 'main' into forward-cli-serve-settings
ealmloff Jun 19, 2024
37036bd
Merge branch 'main' into suspense-2.0
ealmloff Jun 19, 2024
e0c6ce3
fix fullstack html data
ealmloff Jun 19, 2024
0f831f1
Merge branch 'main' into suspense-2.0
ealmloff Jun 19, 2024
25f2392
remove drop virtual dom feature
ealmloff Jun 19, 2024
670569b
add a comment about only_write_templates binary size workaround
ealmloff Jun 19, 2024
1064614
remove explicit dependencies from use_server_future
ealmloff Jun 19, 2024
ffed67f
make ErrorContext and SuspenseContext more similar
ealmloff Jun 19, 2024
5731885
Tweak: small tweaks to tomls to make diff smaller
jkelleyrtp Jun 20, 2024
20310da
only rerun components under suspense after the initial placeholders a…
ealmloff Jun 20, 2024
b7d693a
add module docs for suspense
ealmloff Jun 20, 2024
e557dd9
keep track of when suspense boundaries are resolved
ealmloff Jun 20, 2024
8ab1650
start implementing JS out of order streaming
ealmloff Jun 20, 2024
6c6674f
fix core tests
ealmloff Jun 20, 2024
f1c9fe1
implement the server side of suspense with js
ealmloff Jun 21, 2024
f41c5f0
fix streaming ssr with nested suspense
ealmloff Jun 21, 2024
7792e57
move streaming ssr code into fullstack
ealmloff Jun 21, 2024
24acc14
revert minification changes
ealmloff Jun 21, 2024
b880101
serialize server future data as the html streams
ealmloff Jun 21, 2024
0b7964c
start loading scripts wasm immediately instead of defering the script
ealmloff Jun 24, 2024
14364c3
very basic nested suspense example working with minimal html updates
ealmloff Jun 25, 2024
7e24e02
clean up some suspense/error docs
ealmloff Jun 25, 2024
999da9a
fix hydrating nested pending server futures
ealmloff Jun 25, 2024
54ac590
sort resolved boundaries by height
ealmloff Jun 25, 2024
8751e5c
Fix disconnecting clients while streaming
ealmloff Jun 25, 2024
7bf9712
fix static generation crate
ealmloff Jun 25, 2024
7b2df8d
don't insert extra divs when hydrating streamed chunks
ealmloff Jun 25, 2024
ebf710c
wait to swap in the elements until they are hydrated
ealmloff Jun 25, 2024
19f6d6f
remove inline streaming script
ealmloff Jun 25, 2024
dc7808e
hackernews partially working
ealmloff Jun 25, 2024
9f303ba
fix spa mode
ealmloff Jun 25, 2024
c2368e9
banish the open shadow dom
ealmloff Jun 25, 2024
77569e2
fix removing placeholder
ealmloff Jun 25, 2024
b24966c
set up streaming playwright test
ealmloff Jun 25, 2024
1f19fc2
Merge branch 'main' into forward-cli-serve-settings
ealmloff Jun 26, 2024
41dbdd6
run web playwright tests on 9999 to avoid port conflicts with other l…
ealmloff Jun 26, 2024
845d6de
remove suspense nodes if the suspense boundary is replaced before the…
ealmloff Jun 26, 2024
e1388e8
ignore hydration of removed suspense boundaries
ealmloff Jun 26, 2024
bdd0bfd
use path based indexing to fix hydrating suspense after parent suspen…
ealmloff Jun 26, 2024
04d0f0b
re-export dioxus error
ealmloff Jun 26, 2024
8d23979
remove resolved suspense divs if the suspense boundary has been removed
ealmloff Jun 26, 2024
b54a030
Fix client side initialized server futures
ealmloff Jun 26, 2024
429fd8b
ignore comment nodes while traversing nodes in core to avoid lists ge…
ealmloff Jun 26, 2024
6033d36
Pass initial hydration data to the client
ealmloff Jun 26, 2024
2210273
hide pre nodes
ealmloff Jun 27, 2024
537fbf3
don't panic if reclaiming an element fails
ealmloff Jun 27, 2024
038ff6c
fix scope stack when polling tasks
ealmloff Jun 27, 2024
837fc35
improve deserialization out of length message
ealmloff Jun 27, 2024
a8f8c93
Ok(VNode::placeholder()) -> VNode::empty()
ealmloff Jun 27, 2024
4b82654
fix typo in rsx usage
ealmloff Jun 27, 2024
b0cf17e
restore testing changes from suspense example
ealmloff Jun 27, 2024
9818d69
clean up some logs and comments
ealmloff Jun 27, 2024
0de7282
fix playwright tests
ealmloff Jun 27, 2024
8f0b0e2
clean up more changes in core
ealmloff Jun 27, 2024
bff3e26
clean up core tests
ealmloff Jun 27, 2024
bf36c59
remove anymap dependency
ealmloff Jun 27, 2024
06a82a8
clean up changes to hooks
ealmloff Jun 27, 2024
37813fc
clean up changes in the router, rsx, and web
ealmloff Jun 27, 2024
1e5d392
revert changes to axum-hello-world
ealmloff Jun 27, 2024
be01bea
fix use_server_future
ealmloff Jun 27, 2024
b429835
fix clippy in dioxus-core
ealmloff Jun 27, 2024
3e3bb31
check that the next or previous node exist before checking if we shou…
ealmloff Jun 27, 2024
329bd0f
fix formatting
ealmloff Jun 27, 2024
cfd9c0b
Merge branch 'forward-cli-serve-settings' into suspense-2.0
ealmloff Jun 27, 2024
2e44bdf
fix suspense playwright test
ealmloff Jun 27, 2024
f7632c7
remove unused suspense code
ealmloff Jun 27, 2024
76bd807
add more suspense playwright tests
ealmloff Jun 27, 2024
469ad8d
add more docs for error boundaries
ealmloff Jun 27, 2024
6d1e142
fix suspense core tests
ealmloff Jun 27, 2024
6faceff
fix ErrorBoundary example
ealmloff Jun 27, 2024
1e47be5
Merge branch 'main' into suspense-2.0
ealmloff Jun 27, 2024
5aaabdd
remove a bunch of debug logging in js
ealmloff Jun 27, 2024
32bbe4a
fix router failure_external_navigation
ealmloff Jun 27, 2024
677aa0c
use absolute paths in the interpreter build.rs
ealmloff Jun 27, 2024
b08a93c
strip '\r' while hashing ts files
ealmloff Jun 27, 2024
25e5437
add a wrapper with a default error boundary and suspense boundary
ealmloff Jun 27, 2024
7e33718
restore hot reloading
ealmloff Jun 27, 2024
d0f1803
ignore non-ts files when hashing
ealmloff Jun 28, 2024
7a0fb84
sort ts files before hashing them
ealmloff Jun 28, 2024
7a5fb3b
fix rsx tests
ealmloff Jun 28, 2024
10ab7e3
fix fullstack doc tests
ealmloff Jun 28, 2024
0216069
fix core tests
ealmloff Jun 28, 2024
1575089
fix axum auth example
ealmloff Jun 28, 2024
09c778b
update suspense hydration diagram
ealmloff Jun 28, 2024
4da2ef6
longer playwright build limit
ealmloff Jun 28, 2024
11ec308
tiny fixes - spelling, formatting
jkelleyrtp Jun 28, 2024
1587f55
Merge branch 'main' into pr/ealmloff/2365
jkelleyrtp Jun 28, 2024
ef3ce94
update diagram link
ealmloff Jun 29, 2024
2fdb5fa
remove comment and template nodes for suspense placeholders
ealmloff Jul 1, 2024
468bf94
remove comment nodes as we hydrate text
ealmloff Jul 1, 2024
3195b25
simplify hackernews example
ealmloff Jul 1, 2024
e770c04
clean up hydrating text nodes
ealmloff Jul 1, 2024
fd60996
switch to a separate environment variable for the base path for small…
ealmloff Jul 1, 2024
cc36100
clean up file system html trait
ealmloff Jul 1, 2024
318969c
fix form data
ealmloff Jul 1, 2024
0e8c5b0
move streaming code into fullstack
ealmloff Jul 1, 2024
742498a
implement serialize and deserialize for CapturedError
ealmloff Jul 1, 2024
1599e40
remove waits in the nested suspense playwright spec
ealmloff Jul 1, 2024
c8ea3cc
force sequential fullstack builds for CI
ealmloff Jul 1, 2024
e6f4d93
longer nested suspense delay for CI
ealmloff Jul 1, 2024
bc69d00
fix --force-sequential flag
ealmloff Jul 2, 2024
eb1a177
wait to launch server until client build is done
ealmloff Jul 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
425 changes: 350 additions & 75 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ members = [
"packages/fullstack/examples/axum-streaming",
"packages/fullstack/examples/axum-desktop",
"packages/fullstack/examples/axum-auth",
"packages/fullstack/examples/hackernews",
"packages/static-generation/examples/simple",
"packages/static-generation/examples/router",
"packages/static-generation/examples/github-pages",
Expand All @@ -46,6 +47,8 @@ members = [
"packages/playwright-tests/liveview",
"packages/playwright-tests/web",
"packages/playwright-tests/fullstack",
"packages/playwright-tests/suspense-carousel",
"packages/playwright-tests/nested-suspense",
]
exclude = ["examples/mobile_demo", "examples/openid_connect_demo"]

Expand All @@ -61,10 +64,10 @@ dioxus-core-macro = { path = "packages/core-macro", version = "0.5.0" }
dioxus-config-macro = { path = "packages/config-macro", version = "0.5.0" }
dioxus-router = { path = "packages/router", version = "0.5.0" }
dioxus-router-macro = { path = "packages/router-macro", version = "0.5.0" }
dioxus-html = { path = "packages/html", version = "0.5.0" }
dioxus-html = { path = "packages/html", default-features = false, version = "0.5.0" }
dioxus-html-internal-macro = { path = "packages/html-internal-macro", version = "0.5.0" }
dioxus-hooks = { path = "packages/hooks", version = "0.5.0" }
dioxus-web = { path = "packages/web", version = "0.5.0" }
dioxus-web = { path = "packages/web", default-features = false, version = "0.5.0" }
dioxus-ssr = { path = "packages/ssr", version = "0.5.0", default-features = false }
dioxus-desktop = { path = "packages/desktop", version = "0.5.0", default-features = false }
dioxus-mobile = { path = "packages/mobile", version = "0.5.0" }
Expand Down Expand Up @@ -118,6 +121,9 @@ axum_session_auth = "0.12.1"
axum-extra = "0.9.2"
reqwest = "0.11.24"
owo-colors = "4.0.0"
ciborium = "0.2.1"
base64 = "0.21.0"
once_cell = "1.17.1"

# speed up some macros by optimizing them
[profile.dev.package.insta]
Expand Down Expand Up @@ -275,7 +281,7 @@ required-features = ["desktop"]
doc-scrape-examples = true

[[example]]
name = "error_handle"
name = "errors"
required-features = ["desktop"]
doc-scrape-examples = true

Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ cargo run --example hello_world

[disabled](./disabled.rs) - Disable buttons conditionally

[error_handle](./error_handle.rs) - Handle errors with early return
[errors](./errors.rs) - Handle errors with early return

## Routing

Expand Down
55 changes: 0 additions & 55 deletions examples/error_handle.rs

This file was deleted.

161 changes: 161 additions & 0 deletions examples/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
//! This example showcases how to use the ErrorBoundary component to handle errors in your app.
//!
//! The ErrorBoundary component is a special component that can be used to catch panics and other errors that occur.
//! By default, Dioxus will catch panics during rendering, async, and handlers, and bubble them up to the nearest
//! error boundary. If no error boundary is present, it will be caught by the root error boundary and the app will
//! render the error message as just a string.
//!
//! NOTE: In wasm, panics can currently not be caught by the error boundary. This is a limitation of WASM in rust.
#![allow(non_snake_case)]

use dioxus::prelude::*;

fn main() {
launch(|| rsx! { Router::<Route> {} });
}

/// You can use an ErrorBoundary to catch errors in children and display a warning
fn Simple() -> Element {
rsx! {
GoBackButton { "Home" }
ErrorBoundary {
handle_error: |error: ErrorContext| rsx! {
h1 { "An error occurred" }
pre { "{error:#?}" }
},
ParseNumber {}
}
}
}

#[component]
fn ParseNumber() -> Element {
rsx! {
h1 { "Error handler demo" }
button {
onclick: move |_| {
// You can return a result from an event handler which lets you easily quit rendering early if something fails
let data: i32 = "0.5".parse()?;

println!("parsed {data}");

Ok(())
},
"Click to throw an error"
}
}
}

// You can provide additional context for the Error boundary to visualize
fn Show() -> Element {
rsx! {
GoBackButton { "Home" }
div {
ErrorBoundary {
handle_error: |errors: ErrorContext| {
rsx! {
for error in errors.errors() {
if let Some(error) = error.show() {
{error}
} else {
pre {
color: "red",
"{error}"
}
}
}
}
},
ParseNumberWithShow {}
}
}
}
}

#[component]
fn ParseNumberWithShow() -> Element {
rsx! {
h1 { "Error handler demo" }
button {
onclick: move |_| {
let request_data = "0.5";
let data: i32 = request_data.parse()
// You can attach rsx to results that can be displayed in the Error Boundary
.show(|_| rsx!{
div {
background_color: "red",
border: "black",
border_width: "2px",
border_radius: "5px",
p { "Failed to parse data" }
Link {
to: Route::Home {},
"Go back to the homepage"
}
}
})?;

println!("parsed {data}");

Ok(())
},
"Click to throw an error"
}
}
}

// On desktop, dioxus will catch panics in components and insert an error automatically
fn Panic() -> Element {
rsx! {
GoBackButton { "Home" }
ErrorBoundary {
handle_error: |errors: ErrorContext| rsx! {
h1 { "Another error occurred" }
pre { "{errors:#?}" }
},
ComponentPanic {}
}
}
}

#[component]
fn ComponentPanic() -> Element {
panic!("This component panics")
}

#[derive(Routable, Clone, Debug, PartialEq)]
enum Route {
#[route("/")]
Home {},
#[route("/simple")]
Simple {},
#[route("/panic")]
Panic {},
#[route("/show")]
Show {},
}

fn Home() -> Element {
rsx! {
ul {
li {
Link {
to: Route::Simple {},
"Simple errors"
}
}
li {
Link {
to: Route::Panic {},
"Capture panics"
}
}
li {
Link {
to: Route::Show {},
"Show errors"
}
}
}
}
}
10 changes: 5 additions & 5 deletions examples/rsx_usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,13 @@ fn app() -> Element {

// Can pass in props directly as an expression
{
let props = TallerProps {a: "hello", children: None };
let props = TallerProps {a: "hello", children: VNode::empty() };
rsx!(Taller { ..props })
}

// Spreading can also be overridden manually
Taller {
..TallerProps { a: "ballin!", children: None },
..TallerProps { a: "ballin!", children: VNode::empty() },
a: "not ballin!"
}

Expand All @@ -193,8 +193,8 @@ fn app() -> Element {
// Type inference can be used too
TypedInput { initial: 10.0 }

// geneircs with the `inline_props` macro
Label { text: "hello geneirc world!" }
// generic with the `inline_props` macro
Label { text: "hello generic world!" }
Label { text: 99.9 }

// Lowercase components work too, as long as they are access using a path
Expand Down Expand Up @@ -283,7 +283,7 @@ where
return rsx! { "{props}" };
}

None
VNode::empty()
}

#[component]
Expand Down
2 changes: 1 addition & 1 deletion examples/shorthand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn app() -> Element {
rsx! {
div { class, id, {&children} }
Component { a, b, c, children, onclick }
Component { a, ..ComponentProps { a: 1, b: 2, c: 3, children: None, onclick: Default::default() } }
Component { a, ..ComponentProps { a: 1, b: 2, c: 3, children: VNode::empty(), onclick: Default::default() } }
}
}

Expand Down
35 changes: 28 additions & 7 deletions examples/suspense.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ fn app() -> Element {
}

h3 { "Illustrious Dog Photo" }
Doggo {}
SuspenseBoundary {
fallback: move |suspense: SuspenseContext| suspense.suspense_placeholder().unwrap_or_else(|| rsx! {
div {
"Loading..."
}
}),
Doggo {}
}
}
}
}
Expand All @@ -49,7 +56,7 @@ fn app() -> Element {
/// actually renders the data.
#[component]
fn Doggo() -> Element {
let mut fut = use_resource(move || async move {
let mut resource = use_resource(move || async move {
#[derive(serde::Deserialize)]
struct DogApi {
message: String,
Expand All @@ -62,12 +69,26 @@ fn Doggo() -> Element {
.await
});

match fut.read_unchecked().as_ref() {
Some(Ok(resp)) => rsx! {
button { onclick: move |_| fut.restart(), "Click to fetch another doggo" }
// You can suspend the future and only continue rendering when it's ready
let value = resource.suspend().with_loading_placeholder(|| {
rsx! {
div {
"Loading doggos..."
}
}
})?;

match value.read_unchecked().as_ref() {
Ok(resp) => rsx! {
button { onclick: move |_| resource.restart(), "Click to fetch another doggo" }
div { img { max_width: "500px", max_height: "500px", src: "{resp.message}" } }
},
Some(Err(_)) => rsx! { div { "loading dogs failed" } },
None => rsx! { div { "loading dogs..." } },
Err(_) => rsx! {
div { "loading dogs failed" }
button {
onclick: move |_| resource.restart(),
"retry"
}
},
}
}
Loading
Loading