Remove dioxus-lib, fix doc imports (#4438)

* remove dioxus lib

* inline some doc items

* fix tests

* test docs

* Fix doc tests

* Pull out dioxus/lib feature

* disable logger and devtools in library feature

* fix cargo doc

* fix cargo doc
This commit is contained in:
Evan Almloff authored and GitHub committed 2025-07-18 14:51:07 -07:00
1 parent 4cb32d372b
commit 98f7667fb4
59 files changed
+216 -530

No files matched your search

+21
View File
@@ -142,6 +142,27 @@ jobs:
env:
RUSTDOCFLAGS: -Dwarnings --document-private-items
test-docs:
if: github.event.pull_request.draft == false
name: Test Docs
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: libwebkit2gtk-4.1-dev libgtk-3-dev libasound2-dev libudev-dev libayatana-appindicator3-dev libxdo-dev libglib2.0-dev
version: 1.0
- name: Install Rust ${{ env.rust_nightly }}
uses: dtolnay/rust-toolchain@nightly
with:
toolchain: ${{ env.rust_nightly }}
- uses: Swatinem/rust-cache@v2
with:
cache-all-crates: "true"
- name: "doc --lib --all-features"
run: |
cargo test --doc --workspace --all-features
check:
if: github.event.pull_request.draft == false
name: Check
Generated
+13 -21
View File
@@ -5443,14 +5443,15 @@ dependencies = [
"ciborium",
"dioxus",
"dioxus-cli-config",
"dioxus-core",
"dioxus-desktop",
"dioxus-devtools",
"dioxus-document",
"dioxus-fullstack-hooks",
"dioxus-fullstack-protocol",
"dioxus-history",
"dioxus-interpreter-js",
"dioxus-isrg",
"dioxus-lib",
"dioxus-router",
"dioxus-server",
"dioxus-web",
@@ -5465,6 +5466,7 @@ dependencies = [
"serde",
"server_fn",
"thiserror 2.0.12",
"tokio",
"tokio-stream",
"tokio-util",
"tower 0.5.2",
@@ -5485,7 +5487,6 @@ dependencies = [
"dioxus-fullstack-protocol",
"dioxus-history",
"dioxus-hooks",
"dioxus-lib",
"dioxus-signals",
"futures-channel",
"serde",
@@ -5601,23 +5602,6 @@ dependencies = [
"walkdir",
]
[[package]]
name = "dioxus-lib"
version = "0.7.0-alpha.3"
dependencies = [
"dioxus",
"dioxus-config-macro",
"dioxus-core",
"dioxus-core-macro",
"dioxus-document",
"dioxus-history",
"dioxus-hooks",
"dioxus-html",
"dioxus-rsx",
"dioxus-signals",
"warnings",
]
[[package]]
name = "dioxus-liveview"
version = "0.7.0-alpha.3"
@@ -5787,11 +5771,15 @@ dependencies = [
"criterion",
"dioxus",
"dioxus-cli-config",
"dioxus-core",
"dioxus-core-macro",
"dioxus-fullstack-hooks",
"dioxus-history",
"dioxus-lib",
"dioxus-hooks",
"dioxus-html",
"dioxus-router",
"dioxus-router-macro",
"dioxus-signals",
"dioxus-ssr",
"percent-encoding",
"rustversion",
@@ -5871,14 +5859,18 @@ dependencies = [
"dashmap 6.1.0",
"dioxus",
"dioxus-cli-config",
"dioxus-core",
"dioxus-core-macro",
"dioxus-devtools",
"dioxus-document",
"dioxus-fullstack-hooks",
"dioxus-fullstack-protocol",
"dioxus-history",
"dioxus-html",
"dioxus-interpreter-js",
"dioxus-isrg",
"dioxus-lib",
"dioxus-router",
"dioxus-signals",
"dioxus-ssr",
"enumset",
"futures-channel",
-3
View File
@@ -2,7 +2,6 @@
resolver = "2"
members = [
"packages/dioxus",
"packages/dioxus-lib",
"packages/core",
"packages/core-types",
"packages/cli",
@@ -32,7 +31,6 @@ members = [
"packages/desktop",
"packages/devtools-types",
"packages/devtools",
"packages/dioxus-lib",
"packages/dioxus",
"packages/document",
"packages/extension",
@@ -139,7 +137,6 @@ version = "0.7.0-alpha.3"
# dependencies that are shared across packages
[workspace.dependencies]
dioxus = { path = "packages/dioxus", version = "0.7.0-alpha.3" }
dioxus-lib = { path = "packages/dioxus-lib", version = "0.7.0-alpha.3", default-features = false }
dioxus-core = { path = "packages/core", version = "0.7.0-alpha.3" }
dioxus-core-types = { path = "packages/core-types", version = "0.7.0-alpha.3" }
dioxus-core-macro = { path = "packages/core-macro", version = "0.7.0-alpha.3" }
+2 -2
View File
@@ -4,7 +4,7 @@
```rust, no_run
# tokio::runtime::Runtime::new().unwrap().block_on(async {
use dioxus_core::{VirtualDom, Event, Element, Mutations};
use dioxus_core::{VirtualDom, Event, Element, Mutations, VNode, ElementId};
let mut vdom = VirtualDom::new(app);
let real_dom = SomeRenderer::new();
@@ -59,7 +59,7 @@ The `dioxus` crate exports the `rsx` macro which transforms a helpful, simpler s
First, start with your app:
```rust
# use dioxus::dioxus_core::Mutations;
# use dioxus::dioxus_core::{Mutations, VirtualDom};
use dioxus::prelude::*;
// First, declare a root component
+3
View File
@@ -109,6 +109,7 @@ pub fn suspend(task: Task) -> Element {
///
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// # use dioxus_core::spawn_isomorphic;
/// // ❌ Do not do requests in isomorphic tasks. It may resolve at a different time on the server and client, causing hydration issues.
/// let mut state = use_signal(|| None);
/// spawn_isomorphic(async move {
@@ -171,6 +172,7 @@ pub fn queue_effect(f: impl FnOnce() + 'static) {
///
/// ```rust
/// use dioxus::prelude::*;
/// use dioxus_core::spawn_forever;
///
/// // The parent component can create and destroy children dynamically
/// fn App() -> Element {
@@ -373,6 +375,7 @@ pub fn schedule_update_any() -> Arc<dyn Fn(ScopeId) + Send + Sync> {
/// Example:
/// ```rust
/// use dioxus::prelude::*;
/// use dioxus_core::use_drop;
///
/// fn app() -> Element {
/// let mut state = use_signal(|| true);
+1
View File
@@ -158,6 +158,7 @@ impl ReactiveContext {
///
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// # use dioxus_core::ReactiveContext;
/// # use futures_util::StreamExt;
/// fn use_simplified_memo(mut closure: impl FnMut() -> i32 + 'static) -> Signal<i32> {
/// use_hook(|| {
+1
View File
@@ -448,6 +448,7 @@ impl Runtime {
///
/// ```rust
/// use dioxus::prelude::*;
/// use dioxus_core::{Runtime, RuntimeGuard};
///
/// fn main() {
/// let virtual_dom = VirtualDom::new(app);
+1
View File
@@ -332,6 +332,7 @@ impl Scope {
///
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// # use dioxus_core::spawn_isomorphic;
/// // ❌ Do not do requests in isomorphic tasks. It may resolve at a different time on the server and client, causing hydration issues.
/// let mut state = use_signal(|| None);
/// spawn_isomorphic(async move {
+1
View File
@@ -121,6 +121,7 @@ impl Runtime {
///
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// # use dioxus_core::spawn_isomorphic;
/// // ❌ Do not do requests in isomorphic tasks. It may resolve at a different time on the server and client, causing hydration issues.
/// let mut state = use_signal(|| None);
/// spawn_isomorphic(async move {
-37
View File
@@ -1,37 +0,0 @@
[package]
name = "dioxus-lib"
version = { workspace = true }
authors = ["Jonathan Kelley", "Dioxus Labs", "ealmloff"]
edition = "2021"
description = "Build fullstack web, desktop, and mobile apps with a single codebase."
license = "MIT OR Apache-2.0"
repository = "https://github.com/DioxusLabs/dioxus/"
homepage = "https://dioxuslabs.com/learn/0.6/"
keywords = ["dom", "ui", "gui", "react", "wasm"]
rust-version = "1.79.0"
[dependencies]
dioxus-core = { workspace = true }
dioxus-html = { workspace = true, optional = true }
dioxus-document = { workspace = true, optional = true }
dioxus-history = { workspace = true, optional = true }
dioxus-core-macro = { workspace = true, optional = true }
dioxus-config-macro = { workspace = true, optional = true }
dioxus-hooks = { workspace = true, optional = true }
dioxus-rsx = { workspace = true, optional = true }
dioxus-signals = { workspace = true, optional = true }
warnings = { workspace = true, optional = true }
[dev-dependencies]
dioxus = { workspace = true }
[features]
default = ["macro", "html", "signals", "hooks", "warnings"]
signals = ["dep:dioxus-signals"]
macro = ["dep:dioxus-core-macro", "dep:dioxus-rsx", "dep:dioxus-config-macro"]
html = ["dep:dioxus-html", "dep:dioxus-document", "dep:dioxus-history"]
hooks = ["dep:dioxus-hooks"]
warnings = ["dep:warnings"]
[package.metadata.docs.rs]
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]
-274
View File
@@ -1,274 +0,0 @@
<div align="center">
<img
src="https://github.com/user-attachments/assets/6c7e227e-44ff-4e53-824a-67949051149c"
alt="Build web, desktop, and mobile apps with a single codebase."
width="100%"
class="darkmode-image"
>
<div>
<a href=https://dioxuslabs.com/learn/0.6/getting_started>Getting Started</a> | <a href="https://dioxuslabs.com/learn/0.6">Book (0.6)</a> | <a href="https://github.com/DioxusLabs/dioxus/tree/main/examples">Examples</a>
</div>
</div>
---
> This crate implements dioxus-lib which is a renderer-free version of Dioxus. This crate is intended to be used by library authors who need a stable core version of dioxus withuot pulling in renderer-related dependencies on accident.
# Overview and Goals
Dioxus makes it easy to quickly build complex user interfaces with Rust. Any Dioxus app can run in the web browser,
as a desktop app, as a mobile app, or anywhere else provided you build the right renderer.
Dioxus is heavily inspired by React, supporting many of the same concepts:
- Hooks for state
- VirtualDom & diffing
- Concurrency, fibers, and asynchronous rendering
- JSX-like templating syntax
If you know React, then you know Dioxus.
Dioxus is _substantially_ more performant than many of the other Rust UI libraries (Yew/Percy) and is _significantly_ more performant
than React—roughly competitive with InfernoJS.
Remember: Dioxus is a library for declaring interactive user interfaces—it is not a dedicated renderer. Most 1st party renderers for Dioxus currently only support web technologies.
## Brief Overview
All Dioxus apps are built by composing functions that return an `Element`.
To launch an app, we use the `launch` method and use features in `Cargo.toml` to specify which renderer we want to use. In the launch function, we pass the app's root `Component`.
```rust, no_run
use dioxus::prelude::*;
fn main() {
dioxus::launch(App);
}
// The #[component] attribute streamlines component creation.
// It's not required, but highly recommended. For example, UpperCamelCase components will not generate a warning.
#[component]
fn App() -> Element {
rsx! { "hello world!" }
}
```
## Elements & your first component
To assemble UI trees with Dioxus, you need to use the `render` function on
something called `LazyNodes`. To produce `LazyNodes`, you can use the `rsx!`
macro or the NodeFactory API. For the most part, you want to use the `rsx!`
macro.
Any element in `rsx!` can have attributes, listeners, and children. For
consistency, we force all attributes and listeners to be listed _before_
children.
```rust, ignore
let value = "123";
rsx! {
div {
class: "my-class {value}", // <--- attribute
onclick: move |_| info!("clicked!"), // <--- listener
h1 { "hello world" }, // <--- child
}
}
```
The `rsx!` macro accepts attributes in "struct form". Any rust expression contained within curly braces that implements `IntoIterator<Item = impl IntoVNode>` will be parsed as a child. We make two exceptions: both `for` loops and `if` statements are parsed where their body is parsed as a child.
```rust, ignore
rsx! {
div {
for _ in 0..10 {
span { "hello world" }
}
}
}
```
The `rsx!` macro is what generates the `Element` that our components return.
```rust, ignore
#[component]
fn Example() -> Element {
rsx!{ "hello world" }
}
```
Putting everything together, we can write a simple component that renders a list of
elements:
```rust, ignore
#[component]
fn App() -> Element {
let name = "dave";
rsx! {
h1 { "Hello, {name}!" }
div { class: "my-class", id: "my-id",
for i in 0..5 {
div { "FizzBuzz: {i}" }
}
}
}
}
```
## Components
We can compose these function components to build a complex app. Each new
component we design must take some Properties. For components with no explicit
properties we can omit the type altogether.
In Dioxus, all properties are memoized by default, and this implement both Clone and PartialEq. For props you can't clone, simply wrap the fields in a ReadOnlySignal and Dioxus will handle the wrapping for you.
```rust, ignore
#[component]
fn App() -> Element {
rsx! {
Header {
title: "My App",
color: "red",
}
}
}
```
Our `Header` component takes a `title` and a `color` property, which we
declare on an explicit `HeaderProps` struct.
```rust, ignore
// The `Props` derive macro lets us add additional functionality to how props are interpreted.
#[derive(Props, PartialEq)]
struct HeaderProps {
title: String,
color: String,
}
#[component]
fn Header(props: HeaderProps) -> Element {
rsx! {
div {
background_color: "{props.color}"
h1 { "{props.title}" }
}
}
}
```
The `#[component]` macro also allows you to derive the props
struct from function arguments:
```rust, ignore
#[component]
fn Header(title: String, color: String) -> Element {
rsx! {
div {
background_color: "{color}"
h1 { "{title}" }
}
}
}
```
Components that begin with an uppercase letter may be called with
the traditional (for React) curly-brace syntax like so:
```rust, ignore
rsx! {
Header { title: "My App" }
}
```
## Hooks
While components are reusable forms of UI elements, hooks are reusable forms
of logic. Hooks provide us a way of retrieving state from Dioxus' internal `Scope` and using
it to render UI elements.
By convention, all hooks are functions that should start with `use_`. We can
use hooks to define the state and modify it from within listeners.
```rust, ignore
#[component]
fn App() -> Element {
let name = use_signal(|| "world");
rsx! { "hello {name}!" }
}
```
Hooks are sensitive to how they are used. To use hooks, you must abide by the
["rules of hooks"](https://dioxuslabs.com/learn/0.6/reference/hooks#rules-of-hooks):
- Functions with "use\_" should not be called in callbacks
- Functions with "use\_" should not be called out of order
- Functions with "use\_" should not be called in loops or conditionals
In a sense, hooks let us add a field of state to our component without declaring
an explicit state struct. However, this means we need to "load" the struct in the right
order. If that order is wrong, then the hook will pick the wrong state and panic.
Most hooks you'll write are simply compositions of other hooks:
```rust, ignore
fn use_username(d: Uuid) -> bool {
let users = use_context::<Users>();
users.get(&id).map(|user| user.logged_in).ok_or(false)
}
```
To create entirely new foundational hooks, we can use the `use_hook` method.
```rust, ignore
fn use_mut_string() -> String {
use_hook(|_| "Hello".to_string())
}
```
If you want to extend Dioxus with some new functionality, you'll probably want to implement a new hook from scratch.
## Putting it all together
Using components, templates, and hooks, we can build a simple app.
```rust, ignore
use dioxus::prelude::*;
fn main() {
dioxus::launch(App);
}
#[component]
fn App() -> Element {
let mut count = use_signal(|| 0);
rsx!(
div { "Count: {count}" }
button { onclick: move |_| count += 1, "Increment" }
button { onclick: move |_| count -= 1, "Decrement" }
)
}
```
## Features
This overview doesn't cover everything. Make sure to check out the tutorial and reference guide on the official
website for more details.
Beyond this overview, Dioxus supports:
- Server-side rendering
- Concurrent rendering (with async support)
- Web/Desktop/Mobile support
- Pre-rendering and rehydration
- Fragments, Portals, and Suspense
- Inline-styles
- Custom event handlers
- Custom elements
- Basic fine-grained reactivity (IE SolidJS/Svelte)
- and more!
Build cool things ✌️
-69
View File
@@ -1,69 +0,0 @@
#![doc = include_str!("../README.md")]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/79236386")]
#![doc(html_favicon_url = "https://avatars.githubusercontent.com/u/79236386")]
pub use dioxus_core as core;
#[cfg(feature = "hooks")]
pub use dioxus_hooks as hooks;
#[cfg(feature = "signals")]
pub use dioxus_signals as signals;
pub mod events {
// #[cfg(feature = "html")]
// pub use dioxus_html::prelude::*;
}
#[cfg(feature = "html")]
pub use dioxus_html as html;
#[cfg(feature = "html")]
pub use dioxus_document as document;
#[cfg(feature = "html")]
pub use dioxus_history as history;
#[cfg(feature = "macro")]
pub use dioxus_rsx as rsx;
#[cfg(feature = "macro")]
pub use dioxus_core_macro as core_macro;
#[cfg(feature = "warnings")]
pub use warnings;
pub mod prelude {
#[cfg(feature = "html")]
#[cfg_attr(docsrs, doc(cfg(feature = "html")))]
pub use dioxus_history::{history, History};
#[cfg(feature = "hooks")]
pub use crate::hooks::*;
#[cfg(feature = "signals")]
pub use dioxus_signals::*;
#[cfg(feature = "macro")]
#[allow(deprecated)]
pub use dioxus_core_macro::{component, rsx, Props};
#[cfg(feature = "macro")]
pub use dioxus_config_macro::*;
#[cfg(feature = "html")]
pub use dioxus_html as dioxus_elements;
#[cfg(feature = "html")]
pub use dioxus_elements::{events::*, global_attributes, svg_attributes, traits::*};
pub use dioxus_core;
pub use dioxus_core::{
consume_context, provide_context, spawn, suspend, try_consume_context, use_hook, Attribute,
Callback, Component, Context, Element, ErrorBoundary, ErrorContext, Event, EventHandler,
Fragment, HasAttributes, IntoDynNode, RenderError, ScopeId, SuspenseBoundary,
SuspenseContext, SuspenseExtension, VNode, VirtualDom,
};
}
+8 -3
View File
@@ -41,20 +41,25 @@ dioxus-devtools = { workspace = true, optional = true }
[features]
default = [
"launch",
"devtools",
"logger",
"lib"
]
# All features recommended for use in libraries
lib = [
"macro",
"html",
"signals",
"hooks",
"launch",
"mounted",
"file_engine",
"document",
"asset",
"devtools",
"logger",
"warnings",
"cli-config",
]
# The minimal set of features required to use dioxus renderers for minimal binary size
minimal = ["macro", "html", "signals", "hooks", "launch"]
signals = ["dep:dioxus-signals"]
macro = ["dep:dioxus-core-macro"]
+19 -1
View File
@@ -26,6 +26,7 @@
#![cfg_attr(docsrs, feature(doc_cfg))]
pub use dioxus_core;
#[doc(inline)]
pub use dioxus_core::{CapturedError, Ok, Result};
#[cfg(feature = "launch")]
@@ -127,27 +128,33 @@ pub use subsecond;
pub mod prelude {
#[cfg(feature = "document")]
#[cfg_attr(docsrs, doc(cfg(feature = "document")))]
#[doc(inline)]
pub use dioxus_document as document;
#[cfg(feature = "document")]
#[cfg_attr(docsrs, doc(cfg(feature = "document")))]
#[doc(inline)]
pub use dioxus_history::{history, History};
#[cfg(feature = "launch")]
#[cfg_attr(docsrs, doc(cfg(feature = "launch")))]
#[doc(inline)]
pub use crate::launch::*;
#[cfg(feature = "hooks")]
#[cfg_attr(docsrs, doc(cfg(feature = "hooks")))]
#[doc(inline)]
pub use crate::hooks::*;
#[cfg(feature = "signals")]
#[cfg_attr(docsrs, doc(cfg(feature = "signals")))]
#[doc(inline)]
pub use dioxus_signals::*;
#[cfg(feature = "macro")]
#[cfg_attr(docsrs, doc(cfg(feature = "macro")))]
#[allow(deprecated)]
#[doc(inline)]
pub use dioxus_core_macro::{component, rsx, Props};
#[cfg(feature = "launch")]
@@ -160,9 +167,15 @@ pub mod prelude {
#[cfg(feature = "html")]
#[cfg_attr(docsrs, doc(cfg(feature = "html")))]
#[doc(inline)]
pub use dioxus_elements::{Code, Key, Location, Modifiers};
#[cfg(feature = "html")]
#[cfg_attr(docsrs, doc(cfg(feature = "html")))]
#[doc(no_inline)]
pub use dioxus_elements::{
events::*, extensions::*, global_attributes, keyboard_types, svg_attributes, traits::*,
Code, GlobalAttributesExtension, Key, Location, Modifiers, SvgAttributesExtension,
GlobalAttributesExtension, SvgAttributesExtension,
};
#[cfg(feature = "devtools")]
@@ -173,12 +186,14 @@ pub mod prelude {
#[cfg(feature = "fullstack")]
#[cfg_attr(docsrs, doc(cfg(feature = "fullstack")))]
#[doc(inline)]
pub use dioxus_fullstack::{
server, server_fn, use_server_cached, use_server_future, ServerFnError, ServerFnResult,
};
#[cfg(feature = "server")]
#[cfg_attr(docsrs, doc(cfg(feature = "server")))]
#[doc(inline)]
pub use dioxus_server::{
extract, DioxusRouterExt, DioxusRouterFnExt, FromContext, ServeConfig,
};
@@ -189,6 +204,7 @@ pub mod prelude {
#[cfg(feature = "router")]
#[cfg_attr(docsrs, doc(cfg(feature = "router")))]
#[doc(inline)]
pub use dioxus_router::{
hooks::*, navigator, use_navigator, GoBackButton, GoForwardButton, Link, NavigationTarget,
Outlet, Routable, Router,
@@ -196,12 +212,14 @@ pub mod prelude {
#[cfg(feature = "asset")]
#[cfg_attr(docsrs, doc(cfg(feature = "asset")))]
#[doc(inline)]
pub use manganis::{self, *};
#[cfg(feature = "wasm-split")]
#[cfg_attr(docsrs, doc(cfg(feature = "wasm-split")))]
pub use wasm_splitter as wasm_split;
#[doc(inline)]
pub use dioxus_core::{
consume_context, provide_context, spawn, suspend, try_consume_context, use_hook, Attribute,
Callback, Component, Context, Element, ErrorBoundary, ErrorContext, Event, EventHandler,
+1 -2
View File
@@ -21,8 +21,7 @@ dioxus-history.workspace = true
[dev-dependencies]
dioxus-fullstack = { workspace = true }
dioxus-lib = { workspace = true }
dioxus = { workspace = true }
dioxus = { workspace = true, features = ["fullstack"] }
[features]
web = []
@@ -10,8 +10,7 @@ use serde::{de::DeserializeOwned, Serialize};
///
/// # Example
/// ```rust
/// use dioxus_lib::prelude::*;
/// use dioxus_fullstack::prelude::*;
/// use dioxus::prelude::*;
///
/// fn app() -> Element {
/// let state1 = use_server_cached(|| {
+3 -1
View File
@@ -19,7 +19,8 @@ dioxus_server_macro = { workspace = true }
axum = { workspace = true, optional = true }
tower-http = { workspace = true, optional = true, features = ["fs"] }
dioxus-lib = { workspace = true, features = ["html"] }
dioxus-core = { workspace = true }
dioxus-document = { workspace = true }
generational-box = { workspace = true }
# Dioxus + SSR
@@ -73,6 +74,7 @@ dioxus-history = { workspace = true }
[dev-dependencies]
dioxus = { workspace = true, features = ["fullstack"] }
tokio = { workspace = true, features = ["full"] }
[features]
default = ["devtools", "document", "file_engine", "mounted"]
+2 -1
View File
@@ -86,6 +86,7 @@ Then we can set up dioxus with the axum server:
```rust, no_run
#![allow(non_snake_case)]
use dioxus::prelude::*;
use dioxus_fullstack::ServeConfig;
// The entry point for the server
#[cfg(feature = "server")]
@@ -99,7 +100,7 @@ async fn main() {
let router = axum::Router::new()
// You can add a dioxus application to the router with the `serve_dioxus_application` method
// This will add a fallback route to the router that will serve your component and server functions
.serve_dioxus_application(ServeConfigBuilder::default(), App);
.serve_dioxus_application(ServeConfig::new().unwrap(), App);
// Finally, we can launch the server
let router = router.into_make_service();
+1 -1
View File
@@ -1,6 +1,6 @@
This method interacts with information from the current request. The request may come from:
1. The initial SSR render if this method called from a [`Component`](dioxus_lib::prelude::component) or a [`server`](dioxus_server) function that is called during the initial render
1. The initial SSR render if this method called from a [`Component`](dioxus_core_macro::component) or a [`server`](dioxus_server) function that is called during the initial render
```rust
# use dioxus::prelude::*;
+3 -11
View File
@@ -4,7 +4,7 @@ use std::{
str::FromStr,
};
use dioxus_lib::core::{CapturedError, RenderError};
use dioxus_core::{CapturedError, RenderError};
use serde::{de::DeserializeOwned, Serialize};
use server_fn::{
codec::JsonEncoding,
@@ -33,7 +33,7 @@ pub type ServerFnResult<T = (), E = String> = std::result::Result<T, ServerFnErr
///
/// You can use the [`ServerFnError`] type in the Error type of your server function result or use the [`ServerFnResult`]
/// type as the return type of your server function. When you call the server function, you can handle the error directly
/// or convert it into a [`CapturedError`] to throw into the nearest [`ErrorBoundary`](dioxus_lib::prelude::ErrorBoundary).
/// or convert it into a [`CapturedError`] to throw into the nearest [`ErrorBoundary`](dioxus_core::ErrorBoundary).
///
/// ```rust
/// use dioxus::prelude::*;
@@ -137,16 +137,8 @@ impl ServerFnError {
/// use dioxus::prelude::*;
/// use serde::{Serialize, Deserialize};
///
/// #[derive(Serialize, Deserialize, Debug)]
/// struct MyCustomError;
/// impl std::fmt::Display for MyCustomError {
/// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
/// write!(f, "My custom error")
/// }
/// }
///
/// #[server]
/// async fn server_function() -> ServerFnResult<String, MyCustomError> {
/// async fn server_function() -> ServerFnResult<String> {
/// // Return your custom error
/// Err(ServerFnError::new("Something went wrong"))
/// }
+1 -1
View File
@@ -1,6 +1,6 @@
//! On the client, we use the [`WebDocument`] implementation to render the head for any elements that were not rendered on the server.
use dioxus_lib::document::*;
use dioxus_document::*;
use dioxus_web::WebDocument;
fn head_element_written_on_server() -> bool {
-1
View File
@@ -24,7 +24,6 @@ impl MemoryHistory {
/// Create a [`MemoryHistory`] starting at `path`.
///
/// ```rust
/// # use dioxus_router::prelude::*;
/// # use dioxus::prelude::*;
/// # #[component]
/// # fn Index() -> Element { VNode::empty() }
+3 -3
View File
@@ -54,7 +54,7 @@ impl AssetOptions {
/// Create a new css asset builder
///
/// ```rust
/// # use manganis::{asset, Asset, CssAssetOptions};
/// # use manganis::{asset, Asset, AssetOptions};
/// const _: Asset = asset!("/assets/style.css", AssetOptions::css());
/// ```
pub const fn css() -> AssetOptionsBuilder<CssAssetOptions> {
@@ -68,7 +68,7 @@ impl AssetOptionsBuilder<CssAssetOptions> {
/// Minifying the css can make your site load faster by loading less data
///
/// ```rust
/// # use manganis::{asset, Asset, CssAssetOptions};
/// # use manganis::{asset, Asset, AssetOptions};
/// const _: Asset = asset!("/assets/style.css", AssetOptions::css().with_minify(false));
/// ```
pub const fn with_minify(mut self, minify: bool) -> Self {
@@ -81,7 +81,7 @@ impl AssetOptionsBuilder<CssAssetOptions> {
/// Preloading css will make the image start to load as soon as possible. This is useful for css that is used soon after the page loads or css that may not be used immediately, but should start loading sooner
///
/// ```rust
/// # use manganis::{asset, Asset, CssAssetOptions};
/// # use manganis::{asset, Asset, AssetOptions};
/// const _: Asset = asset!("/assets/style.css", AssetOptions::css().with_preload(true));
/// ```
pub const fn with_preload(mut self, preload: bool) -> Self {
@@ -57,7 +57,7 @@ impl AssetOptions {
/// Create a new css module asset builder
///
/// ```rust
/// # use manganis::{asset, Asset, CssModuleAssetOptions};
/// # use manganis::{asset, Asset, AssetOptions};
/// const _: Asset = asset!("/assets/style.css", AssetOptions::css_module());
/// ```
pub const fn css_module() -> AssetOptionsBuilder<CssModuleAssetOptions> {
@@ -127,7 +127,7 @@ impl AssetOptions {
/// Create a new image asset builder
///
/// ```rust
/// # use manganis::{asset, Asset, ImageAssetOptions};
/// # use manganis::{asset, Asset, AssetOptions};
/// const _: Asset = asset!("/assets/image.png", AssetOptions::image());
/// ```
pub const fn image() -> AssetOptionsBuilder<ImageAssetOptions> {
@@ -141,7 +141,7 @@ impl AssetOptionsBuilder<ImageAssetOptions> {
/// Preloading an image will make the image start to load as soon as possible. This is useful for images that will be displayed soon after the page loads or images that may not be visible immediately, but should start loading sooner
///
/// ```rust
/// # use manganis::{asset, Asset, ImageAssetOptions};
/// # use manganis::{asset, Asset, AssetOptions};
/// const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_preload(true));
/// ```
pub const fn with_preload(mut self, preload: bool) -> Self {
@@ -154,7 +154,7 @@ impl AssetOptionsBuilder<ImageAssetOptions> {
/// Choosing the right format can make your site load much faster. Webp and avif images tend to be a good default for most images
///
/// ```rust
/// # use manganis::{asset, Asset, ImageAssetOptions, ImageFormat};
/// # use manganis::{asset, Asset, AssetOptions, ImageFormat};
/// const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_format(ImageFormat::Webp));
/// ```
pub const fn with_format(mut self, format: ImageFormat) -> Self {
@@ -168,7 +168,7 @@ impl AssetOptionsBuilder<ImageAssetOptions> {
/// they compress images well
///
/// ```rust
/// # use manganis::{asset, Asset, ImageAssetOptions, ImageFormat};
/// # use manganis::{asset, Asset, AssetOptions, ImageFormat};
/// const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_avif());
/// ```
pub const fn with_avif(self) -> Self {
@@ -181,7 +181,7 @@ impl AssetOptionsBuilder<ImageAssetOptions> {
/// they compress images well
///
/// ```rust
/// # use manganis::{asset, Asset, ImageAssetOptions, ImageFormat};
/// # use manganis::{asset, Asset, AssetOptions, ImageFormat};
/// const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_webp());
/// ```
pub const fn with_webp(self) -> Self {
@@ -193,7 +193,7 @@ impl AssetOptionsBuilder<ImageAssetOptions> {
/// Jpeg images compress much better than [`ImageFormat::Png`], but worse than [`ImageFormat::Webp`] or [`ImageFormat::Avif`]
///
/// ```rust
/// # use manganis::{asset, Asset, ImageAssetOptions, ImageFormat};
/// # use manganis::{asset, Asset, AssetOptions, ImageFormat};
/// const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_jpg());
/// ```
pub const fn with_jpg(self) -> Self {
@@ -205,7 +205,7 @@ impl AssetOptionsBuilder<ImageAssetOptions> {
/// Png images don't compress very well, so they are not recommended for large images
///
/// ```rust
/// # use manganis::{asset, Asset, ImageAssetOptions, ImageFormat};
/// # use manganis::{asset, Asset, AssetOptions, ImageFormat};
/// const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_png());
/// ```
pub const fn with_png(self) -> Self {
@@ -217,7 +217,7 @@ impl AssetOptionsBuilder<ImageAssetOptions> {
/// If you only use the image in one place, you can set the size of the image to the size it will be displayed at. This will make the image load faster
///
/// ```rust
/// # use manganis::{asset, Asset, ImageAssetOptions, ImageSize};
/// # use manganis::{asset, Asset, AssetOptions, ImageSize};
/// const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_size(ImageSize::Manual { width: 512, height: 512 }));
/// ```
pub const fn with_size(mut self, size: ImageSize) -> Self {
+3 -3
View File
@@ -55,7 +55,7 @@ impl AssetOptions {
/// Create a new js asset builder
///
/// ```rust
/// # use manganis::{asset, Asset, JsAssetOptions};
/// # use manganis::{asset, Asset, AssetOptions};
/// const _: Asset = asset!("/assets/script.js", AssetOptions::js());
/// ```
pub const fn js() -> AssetOptionsBuilder<JsAssetOptions> {
@@ -69,7 +69,7 @@ impl AssetOptionsBuilder<JsAssetOptions> {
/// Minifying the js can make your site load faster by loading less data
///
/// ```rust
/// # use manganis::{asset, Asset, JsAssetOptions};
/// # use manganis::{asset, Asset, AssetOptions};
/// const _: Asset = asset!("/assets/script.js", AssetOptions::js().with_minify(false));
/// ```
#[allow(unused)]
@@ -83,7 +83,7 @@ impl AssetOptionsBuilder<JsAssetOptions> {
/// Preloading the javascript will make the javascript start to load as soon as possible. This is useful for javascript that will be used soon after the page loads or javascript that may not be used immediately, but should start loading sooner
///
/// ```rust
/// # use manganis::{asset, Asset, JsAssetOptions};
/// # use manganis::{asset, Asset, AssetOptions};
/// const _: Asset = asset!("/assets/script.js", AssetOptions::js().with_preload(true));
/// ```
#[allow(unused)]
@@ -62,10 +62,10 @@ impl AssetOptions {
/// A builder for [`AssetOptions`]
///
/// ```rust
/// # use manganis::AssetOptionsBuilder;
/// # use manganis::{AssetOptions, Asset, asset};
/// static ASSET: Asset = asset!(
/// "image.png",
/// AssetOptionsBuilder::new()
/// "/assets/style.css",
/// AssetOptions::builder()
/// .with_hash_suffix(false)
/// );
/// ```
@@ -130,8 +130,8 @@ impl<T> AssetOptionsBuilder<T> {
/// ```rust
/// #[used]
/// static ASSET: manganis::Asset = manganis::asset!(
/// "path/to/asset.png",
/// AssetVariant::Unknown.into_asset_options()
/// "/assets/style.css",
/// manganis::AssetOptions::builder()
/// .with_hash_suffix(false)
/// );
/// ```
+9 -9
View File
@@ -45,17 +45,17 @@ use linker::generate_link_section;
/// ```
/// Resize the image at compile time to make the assets file size smaller:
/// ```rust
/// # use manganis::{asset, Asset, ImageAssetOptions, ImageSize};
/// # use manganis::{asset, Asset, AssetOptions, ImageSize};
/// const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_size(ImageSize::Manual { width: 52, height: 52 }));
/// ```
/// Or convert the image at compile time to a web friendly format:
/// ```rust
/// # use manganis::{asset, Asset, ImageAssetOptions, ImageSize, ImageFormat};
/// # use manganis::{asset, Asset, AssetOptions, ImageSize, ImageFormat};
/// const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_format(ImageFormat::Avif));
/// ```
/// You can mark images as preloaded to make them load faster in your app
/// ```rust
/// # use manganis::{asset, Asset, ImageAssetOptions};
/// # use manganis::{asset, Asset, AssetOptions};
/// const _: Asset = asset!("/assets/image.png", AssetOptions::image().with_preload(true));
/// ```
#[proc_macro]
@@ -77,7 +77,7 @@ pub fn asset(input: TokenStream) -> TokenStream {
/// - The asset string path. This is the absolute path (from the crate root) to your CSS module.
/// - An optional `CssModuleAssetOptions` struct to configure the processing of your CSS module.
///
/// ```rust
/// ```rust, ignore
/// css_module!(StylesIdent = "/my.module.css", AssetOptions::css_module());
/// ```
///
@@ -90,7 +90,7 @@ pub fn asset(input: TokenStream) -> TokenStream {
/// - It generates an asset using the `asset!()` macro and automatically inserts it into the app meta.
/// - It generates a struct with snake-case associated constants of your CSS idents.
///
/// ```rust
/// ```rust, ignore
/// // This macro usage:
/// css_module!(Styles = "/mycss.module.css");
///
@@ -99,7 +99,7 @@ pub fn asset(input: TokenStream) -> TokenStream {
///
/// impl Styles {
/// // This can be accessed with `Styles::your_ident`
/// pub const your_ident: &str = "abc",
/// pub const your_ident: &str = "abc";
/// }
/// ```
///
@@ -121,13 +121,13 @@ pub fn asset(input: TokenStream) -> TokenStream {
/// # Variable Visibility
/// If you want your asset or styles constant to be public, you can add the `pub` keyword in front of them.
/// Restricted visibility (`pub(super)`, `pub(crate)`, etc) is also supported.
/// ```rust
/// ```rust, ignore
/// css_module!(pub Styles = "/mycss.module.css");
/// ```
///
/// # Asset Options
/// Similar to the `asset!()` macro, you can pass an optional `CssModuleAssetOptions` to configure a few processing settings.
/// ```rust
/// ```rust, ignore
/// use manganis::CssModuleAssetOptions;
///
/// css_module!(Styles = "/mycss.module.css",
@@ -155,7 +155,7 @@ pub fn asset(input: TokenStream) -> TokenStream {
/// }
/// ```
/// Then you can use the `css_module!()` macro in your Rust project:
/// ```rust
/// ```rust, ignore
/// css_module!(Styles = "/mycss.module.css");
///
/// println!("{}", Styles::header);
+1 -1
View File
@@ -12,7 +12,7 @@ const AVIF_ASSET: Asset = manganis::asset!("/assets/image.png");
AVIF_ASSET will be set to a new file name that will be served by some CLI. That file can be collected by any package that depends on the component library.
```rust
use manganis::{ImageFormat, ImageAssetOptions, Asset, asset, ImageSize};
use manganis::{ImageFormat, Asset, asset, ImageSize, AssetOptions};
// You can collect arbitrary files. Absolute paths are resolved relative to the package root
const _: Asset = asset!("/assets/script.js");
+6 -2
View File
@@ -10,7 +10,11 @@ homepage = "https://dioxuslabs.com"
keywords = ["dom", "ui", "gui", "react", "wasm"]
[dependencies]
dioxus-lib = { workspace = true, default-features = false, features = ["signals", "macro", "hooks"] }
dioxus-core = { workspace = true }
dioxus-core-macro = { workspace = true }
dioxus-signals = { workspace = true }
dioxus-hooks = { workspace = true }
dioxus-html = { workspace = true, optional = true }
dioxus-history = { workspace = true }
dioxus-router-macro = { workspace = true }
dioxus-fullstack-hooks = { workspace = true, optional = true }
@@ -24,7 +28,7 @@ rustversion = { workspace = true }
default = ["html"]
streaming = ["dep:dioxus-fullstack-hooks"]
wasm-split = []
html = ["dioxus-lib/html"]
html = ["dep:dioxus-html"]
[dev-dependencies]
axum = { workspace = true, features = ["ws"] }
-1
View File
@@ -27,7 +27,6 @@ expressiveness.
```rust, no_run
use dioxus::prelude::*;
use dioxus_router::prelude::*;
use std::str::FromStr;
#[rustfmt::skip]
@@ -1,8 +1,8 @@
/// Components that allow the macro to add child routers. This component provides a context
/// to the child router that maps child routes to root routes and vice versa.
use dioxus_lib::prelude::*;
use crate::Routable;
use dioxus_core::{provide_context, try_consume_context, use_hook, Element};
use dioxus_core_macro::{component, Props};
/// Maps a child route into the root router and vice versa
// NOTE: Currently child routers only support simple static prefixes, but this
@@ -53,7 +53,7 @@ impl<R: Routable> PartialEq for ChildRouterProps<R> {
}
}
/// A component that provides a [`History`] to a child router. The `#[child]` attribute on the router macro will insert this automatically.
/// A component that provides a [`History`](dioxus_history::History) to a child router. The `#[child]` attribute on the router macro will insert this automatically.
#[component]
#[allow(missing_docs)]
pub fn ChildRouter<R: Routable>(props: ChildRouterProps<R>) -> Element {
@@ -1,6 +1,10 @@
use dioxus_core::Element;
use dioxus_core_macro::rsx;
use dioxus_html as dioxus_elements;
use dioxus_signals::{GlobalSignal, Readable};
#[allow(deprecated)]
use crate::hooks::use_router;
use dioxus_lib::prelude::*;
/// The default component to render when an external navigation fails.
#[allow(non_snake_case)]
@@ -1,4 +1,7 @@
use dioxus_lib::prelude::*;
use dioxus_core::{Element, VNode};
use dioxus_core_macro::{rsx, Props};
use dioxus_html as dioxus_elements;
use dioxus_signals::{GlobalSignal, Readable};
use tracing::error;
@@ -24,7 +27,6 @@ pub struct HistoryButtonProps {
/// # Example
/// ```rust
/// # use dioxus::prelude::*;
/// # use dioxus_router::prelude::*;
/// #[derive(Clone, Routable)]
/// enum Route {
/// #[route("/")]
@@ -97,7 +99,6 @@ pub fn GoBackButton(props: HistoryButtonProps) -> Element {
/// # Example
/// ```rust
/// # use dioxus::prelude::*;
/// # use dioxus_router::prelude::*;
/// #[derive(Clone, Routable)]
/// enum Route {
/// #[route("/")]
@@ -1,5 +1,7 @@
use dioxus_core::{use_hook, Callback, Element};
use dioxus_core_macro::{component, Props};
use dioxus_history::{provide_history_context, History};
use dioxus_lib::prelude::*;
use dioxus_signals::Owner;
use std::rc::Rc;
+6 -2
View File
@@ -2,7 +2,12 @@
use std::fmt::Debug;
use dioxus_lib::prelude::*;
use dioxus_core::{Attribute, Element, EventHandler, VNode};
use dioxus_core_macro::{rsx, Props};
use dioxus_html::{
self as dioxus_elements, ModifiersInteraction, MountedEvent, MouseEvent, PointerInteraction,
};
use dioxus_signals::{GlobalSignal, Owner, Readable};
use tracing::error;
@@ -91,7 +96,6 @@ impl Debug for LinkProps {
/// # Example
/// ```rust
/// # use dioxus::prelude::*;
/// # use dioxus_router::prelude::*;
///
/// #[derive(Clone, Routable)]
/// enum Route {
+1 -2
View File
@@ -1,5 +1,5 @@
use crate::{outlet::OutletContext, *};
use dioxus_lib::prelude::*;
use dioxus_core::Element;
/// An outlet for the current content.
///
@@ -15,7 +15,6 @@ use dioxus_lib::prelude::*;
/// # Example
/// ```rust
/// # use dioxus::prelude::*;
/// # use dioxus_router::prelude::*;
/// #[derive(Clone, Routable)]
/// #[rustfmt::skip]
/// enum Route {
+4 -3
View File
@@ -1,6 +1,7 @@
use dioxus_lib::prelude::*;
use crate::{provide_router_context, routable::Routable, router_cfg::RouterConfig, Outlet};
use dioxus_core::{provide_context, use_hook, Callback, Element};
use dioxus_core_macro::{rsx, Props};
use dioxus_signals::{GlobalSignal, Owner, Readable};
/// The props for [`Router`].
#[derive(Props)]
@@ -41,7 +42,7 @@ pub fn Router<R: Routable + Clone>(props: RouterProps<R>) -> Element {
});
#[cfg(feature = "streaming")]
use_after_suspense_resolved(|| {
dioxus_hooks::use_after_suspense_resolved(|| {
dioxus_fullstack_hooks::commit_initial_chunk();
});
+1 -1
View File
@@ -9,7 +9,7 @@ use crate::{ExternalNavigationFailure, NavigationTarget, RouterContext};
/// Panics if there is no router present.
pub fn navigator() -> Navigator {
Navigator(
dioxus_lib::core::try_consume_context::<RouterContext>()
dioxus_core::try_consume_context::<RouterContext>()
.expect("A router must be present to use navigator"),
)
}
+3 -3
View File
@@ -1,4 +1,4 @@
use dioxus_lib::core::{provide_context, try_consume_context, use_hook, Element, VNode};
use dioxus_core::{provide_context, try_consume_context, use_hook, Element, VNode};
use crate::{routable::Routable, utils::use_router_internal::use_router_internal};
@@ -75,8 +75,8 @@ impl<R> OutletContext<R> {
/// # Examples
///
/// ```rust, no_run
/// # use dioxus_lib::prelude::*;
/// # use dioxus_router::prelude::{use_outlet_context,Routable};
/// # use dioxus::prelude::*;
/// # use dioxus_router::use_outlet_context;
///
/// # #[derive(Routable,Clone,PartialEq)]
/// # enum MyRouter {
+2 -1
View File
@@ -5,8 +5,9 @@ use std::{
sync::{Arc, Mutex},
};
use dioxus_core::{provide_context, Element, ReactiveContext, ScopeId};
use dioxus_history::history;
use dioxus_lib::{core::ReactiveContext, prelude::*};
use dioxus_signals::{CopyValue, Readable, Signal, Writable};
use crate::{
components::child_router::consume_child_route_mapping, navigation::NavigationTarget,
+1 -2
View File
@@ -1,4 +1,4 @@
use dioxus_lib::core::{try_consume_context, use_hook};
use dioxus_core::{try_consume_context, use_hook};
use crate::{Navigator, RouterContext};
@@ -8,7 +8,6 @@ use crate::{Navigator, RouterContext};
///
/// ```rust
/// # use dioxus::prelude::*;
/// # use dioxus_router::prelude::*;
/// #[derive(Clone, Routable)]
/// enum Route {
/// #[route("/")]
+2 -2
View File
@@ -10,11 +10,11 @@ pub fn use_router() -> RouterContext {
/// Acquire the router without subscribing to updates.
#[doc(alias = "url")]
pub fn router() -> RouterContext {
dioxus_lib::core::consume_context()
dioxus_core::consume_context()
}
/// Try to acquire the router without subscribing to updates.
#[doc(alias = "url")]
pub fn try_router() -> Option<RouterContext> {
dioxus_lib::core::try_consume_context()
dioxus_core::try_consume_context()
}
+1 -1
View File
@@ -82,7 +82,7 @@ pub trait HasProps {
type Props;
}
impl<P> HasProps for dioxus_lib::core::Component<P> {
impl<P> HasProps for dioxus_core::Component<P> {
type Props = P;
}
-2
View File
@@ -30,7 +30,6 @@ pub enum NavigationTarget<R = String> {
///
/// ```rust
/// # use dioxus::prelude::*;
/// # use dioxus_router::prelude::*;
/// # use dioxus_router::navigation::NavigationTarget;
/// # #[component]
/// # fn Index() -> Element {
@@ -50,7 +49,6 @@ pub enum NavigationTarget<R = String> {
///
/// ```rust
/// # use dioxus::prelude::*;
/// # use dioxus_router::prelude::*;
/// # use dioxus_router::navigation::NavigationTarget;
/// # #[component]
/// # fn Index() -> Element {
+4 -3
View File
@@ -1,7 +1,7 @@
#![allow(non_snake_case)]
//! # Routable
use dioxus_lib::core::Element;
use dioxus_core::Element;
use std::iter::FlatMap;
use std::slice::Iter;
use std::{fmt::Display, str::FromStr};
@@ -308,6 +308,7 @@ impl<T: ToQueryArgument<M>, M> Display for DisplayQueryArgument<'_, T, M> {
///
/// ```rust
/// use dioxus::prelude::*;
/// use dioxus_router::FromHashFragment;
///
/// #[derive(Routable, Clone)]
/// #[rustfmt::skip]
@@ -475,6 +476,7 @@ fn full_circle() {
///
/// ```rust
/// use dioxus::prelude::*;
/// use dioxus_router::{ToRouteSegments, FromRouteSegments};
///
/// #[derive(Routable, Clone, PartialEq, Debug)]
/// enum Route {
@@ -566,6 +568,7 @@ fn to_route_segments() {
///
/// ```rust
/// use dioxus::prelude::*;
/// use dioxus_router::{ToRouteSegments, FromRouteSegments};
///
/// #[derive(Routable, Clone, PartialEq, Debug)]
/// enum Route {
@@ -735,7 +738,6 @@ pub trait Routable: FromStr<Err: Display> + Display + Clone + 'static {
///
/// # Example
/// ```rust
/// use dioxus_router::prelude::*;
/// use dioxus::prelude::*;
///
/// #[component]
@@ -803,7 +805,6 @@ pub trait Routable: FromStr<Err: Display> + Display + Clone + 'static {
///
/// # Example
/// ```rust
/// use dioxus_router::prelude::*;
/// use dioxus::prelude::*;
///
/// #[component]
+2 -2
View File
@@ -1,13 +1,13 @@
use crate::{GenericRouterContext, NavigationTarget, Routable, RoutingCallback};
use dioxus_lib::core::Element;
use dioxus_core::Element;
use std::sync::Arc;
/// Global configuration options for the router.
///
/// This implements [`Default`] and follows the builder pattern, so you can use it like this:
/// ```rust,no_run
/// # use dioxus_router::prelude::*;
/// # use dioxus::prelude::*;
/// # use dioxus_router::RouterConfig;
/// # #[component]
/// # fn Index() -> Element {
/// # VNode::empty()
@@ -1,5 +1,5 @@
use crate::RouterContext;
use dioxus_lib::core::{try_consume_context, use_hook};
use dioxus_core::{try_consume_context, use_hook};
/// A private hook to subscribe to the router.
///
+5 -1
View File
@@ -27,7 +27,11 @@ impl ToTokens for ExprNode {
fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) {
let expr = &self.expr;
tokens.append_all(quote! {
{ let ___nodes = (#expr).into_dyn_node(); ___nodes }
{
#[allow(unused_braces)]
let ___nodes = dioxus_core::IntoDynNode::into_dyn_node(#expr);
___nodes
}
})
}
}
+1 -1
View File
@@ -49,7 +49,7 @@ impl ToTokens for ForLoop {
// the temporary is important so we create a lifetime binding
tokens.append_all(quote! {
{
let ___nodes = (#expr).into_iter().map(|#pat| { #body }).into_dyn_node();
let ___nodes = dioxus_core::IntoDynNode::into_dyn_node((#expr).into_iter().map(|#pat| { #body }));
___nodes
}
});
+1 -1
View File
@@ -127,7 +127,7 @@ impl ToTokens for IfChain {
tokens.append_all(quote! {
{
let ___nodes = (#body).into_dyn_node();
let ___nodes = dioxus_core::IntoDynNode::into_dyn_node(#body);
___nodes
}
})
+5 -1
View File
@@ -12,7 +12,11 @@ resolver = "2"
[dependencies]
# dioxus
dioxus-lib = { workspace = true }
dioxus-core = { workspace = true }
dioxus-core-macro = { workspace = true }
dioxus-signals = { workspace = true }
dioxus-document = { workspace = true }
dioxus-html = { workspace = true }
generational-box = { workspace = true }
# server functions
+3 -1
View File
@@ -1,9 +1,10 @@
This method interacts with information from the current request. The request may come from:
1. The initial SSR render if this method called from a [`Component`](dioxus_lib::prelude::component) or a [`server`](crate) function that is called during the initial render
1. The initial SSR render if this method called from a [`Component`](dioxus_core_macro::component) or a [`server`](crate) function that is called during the initial render
```rust
# use dioxus::prelude::*;
use dioxus_server::server_context;
#[component]
fn PrintHtmlRequestInfo() -> Element {
// The server context only exists on the server, so we need to put it behind a server_only! config
@@ -22,6 +23,7 @@ fn PrintHtmlRequestInfo() -> Element {
```rust
# use dioxus::prelude::*;
use dioxus_server::server_context;
#[server]
async fn read_headers() -> ServerFnResult {
// Since we are calling this from a server function, the server context that is may be from the
+6 -6
View File
@@ -1,7 +1,7 @@
//! Configuration for how to serve a Dioxus application
#![allow(non_snake_case)]
use dioxus_lib::prelude::dioxus_core::LaunchConfig;
use dioxus_core::LaunchConfig;
use std::any::Any;
use std::fs::File;
use std::io::Read;
@@ -49,7 +49,7 @@ impl ServeConfigBuilder {
/// // Finally, launch the app with the config
/// LaunchBuilder::new()
/// // Only set the server config if the server feature is enabled
/// .with_cfg(server_only!(ServeConfigBuilder::default().incremental(IncrementalRendererConfig::default())))
/// .with_cfg(server_only!(dioxus_server::ServeConfigBuilder::default().incremental(dioxus_server::IncrementalRendererConfig::default())))
/// .launch(app);
/// ```
pub fn incremental(mut self, cfg: dioxus_isrg::IncrementalRendererConfig) -> Self {
@@ -96,7 +96,7 @@ impl ServeConfigBuilder {
/// LaunchBuilder::new()
/// // Only set the server config if the server feature is enabled
/// .with_cfg(server_only! {
/// ServeConfigBuilder::default().root_id("app")
/// dioxus_server::ServeConfigBuilder::default().root_id("app")
/// })
/// // You also need to set the root id in your web config
/// .with_cfg(web! {
@@ -113,7 +113,7 @@ impl ServeConfigBuilder {
self
}
/// Provide context to the root and server functions. You can use this context while rendering with [`consume_context`](dioxus_lib::prelude::consume_context)
/// Provide context to the root and server functions. You can use this context while rendering with [`consume_context`](dioxus_core::consume_context)
/// or in server functions with [`FromContext`](crate::FromContext).
///
///
@@ -183,7 +183,7 @@ impl ServeConfigBuilder {
}
/// Provide context to the root and server functions. You can use this context
/// while rendering with [`consume_context`](dioxus_lib::prelude::consume_context) or in server functions with [`FromContext`](crate::FromContext).
/// while rendering with [`consume_context`](dioxus_core::consume_context) or in server functions with [`FromContext`](crate::FromContext).
///
///
/// The context providers passed into this method will be called when the context type is requested which may happen many times in the lifecycle of the application.
@@ -246,7 +246,7 @@ impl ServeConfigBuilder {
self
}
/// Provide context to the root and server functions. You can use this context while rendering with [`consume_context`](dioxus_lib::prelude::consume_context)
/// Provide context to the root and server functions. You can use this context while rendering with [`consume_context`](dioxus_core::consume_context)
/// or in server functions with [`FromContext`](crate::FromContext).
///
/// Context will be forwarded from the LaunchBuilder if it is provided.
+9
View File
@@ -47,6 +47,7 @@ impl AtomicResponsePartsModified {
///
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// use dioxus_server::server_context;
/// #[server]
/// async fn read_headers() -> ServerFnResult {
/// let server_context = server_context();
@@ -200,6 +201,7 @@ mod server_fn_impl {
///
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// use dioxus_server::server_context;
/// #[server]
/// async fn set_headers() -> ServerFnResult {
/// let server_context = server_context();
@@ -224,6 +226,7 @@ mod server_fn_impl {
///
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// use dioxus_server::server_context;
/// #[server]
/// async fn set_headers() -> ServerFnResult {
/// let server_context = server_context();
@@ -246,6 +249,7 @@ mod server_fn_impl {
///
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// use dioxus_server::server_context;
/// #[server]
/// async fn set_status() -> ServerFnResult {
/// let server_context = server_context();
@@ -267,6 +271,7 @@ mod server_fn_impl {
///
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// use dioxus_server::server_context;
/// #[server]
/// async fn set_version() -> ServerFnResult {
/// let server_context = server_context();
@@ -288,6 +293,7 @@ mod server_fn_impl {
///
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// use dioxus_server::server_context;
/// #[server]
/// async fn set_version() -> ServerFnResult {
/// let server_context = server_context();
@@ -322,6 +328,7 @@ mod server_fn_impl {
///
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// use dioxus_server::server_context;
/// #[server]
/// async fn read_headers() -> ServerFnResult {
/// let server_context = server_context();
@@ -346,6 +353,7 @@ mod server_fn_impl {
///
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// use dioxus_server::server_context;
/// #[server]
/// async fn read_headers() -> ServerFnResult {
/// let server_context = server_context();
@@ -369,6 +377,7 @@ mod server_fn_impl {
///
/// ```rust, no_run
/// # use dioxus::prelude::*;
/// use dioxus_server::server_context;
/// #[server]
/// async fn read_headers() -> ServerFnResult {
/// let server_context = server_context();
+7 -1
View File
@@ -4,7 +4,13 @@
use std::cell::RefCell;
use dioxus_lib::{document::*, prelude::*};
use dioxus_core::Element;
use dioxus_core_macro::rsx;
use dioxus_document::{
Document, Eval, LinkProps, MetaProps, NoOpDocument, ScriptProps, StyleProps,
};
use dioxus_html as dioxus_elements;
use dioxus_signals::{GlobalSignal, Readable};
use dioxus_ssr::Renderer;
use parking_lot::RwLock;
use std::sync::LazyLock;
+3 -1
View File
@@ -11,8 +11,10 @@ use axum::{
routing::IntoMakeService,
};
use dioxus_cli_config::base_path;
use dioxus_core::Element;
#[cfg(not(target_arch = "wasm32"))]
use dioxus_core::{RenderError, VNode};
use dioxus_devtools::DevserverMsg;
use dioxus_lib::prelude::*;
use futures_util::{stream::FusedStream, StreamExt};
use hyper::body::Incoming;
use hyper_util::server::conn::auto::Builder as HyperBuilder;
+5 -8
View File
@@ -5,16 +5,14 @@ use crate::{
DioxusServerContext,
};
use dioxus_cli_config::base_path;
use dioxus_core::{
has_context, provide_error_boundary, DynamicNode, ErrorContext, ScopeId, SuspenseContext,
VNode, VirtualDom,
};
use dioxus_fullstack_hooks::history::FullstackHistory;
use dioxus_fullstack_hooks::{StreamingContext, StreamingStatus};
use dioxus_fullstack_protocol::{HydrationContext, SerializedHydrationData};
use dioxus_isrg::{CachedRender, IncrementalRendererError, RenderFreshness};
use dioxus_lib::{
core::{
has_context, provide_error_boundary, DynamicNode, ErrorContext, SuspenseContext, VirtualDom,
},
document::Document,
};
use dioxus_router::ParseRouteError;
use dioxus_ssr::Renderer;
use futures_channel::mpsc::Sender;
@@ -23,7 +21,6 @@ use std::{collections::HashMap, fmt::Write, future::Future, rc::Rc, sync::Arc, s
use tokio::task::JoinHandle;
use crate::StreamingMode;
use dioxus_lib::prelude::*;
/// A suspense boundary that is pending with a placeholder in the client
struct PendingSuspenseBoundary {
@@ -210,7 +207,7 @@ impl SsrRendererPool {
let streaming_context = in_root_scope(&virtual_dom, StreamingContext::new);
virtual_dom.provide_root_context(Rc::new(history) as Rc<dyn dioxus_history::History>);
virtual_dom.provide_root_context(document.clone() as Rc<dyn Document>);
virtual_dom.provide_root_context(document.clone() as Rc<dyn dioxus_document::Document>);
virtual_dom.provide_root_context(streaming_context);
// rebuild the virtual dom
+10 -13
View File
@@ -9,7 +9,7 @@ use axum::{
response::IntoResponse,
};
use dioxus_lib::prelude::{Element, VirtualDom};
use dioxus_core::{Element, VirtualDom};
use http::header::*;
use server_fn::ServerFnTraitObj;
use std::path::Path;
@@ -25,8 +25,7 @@ pub trait DioxusRouterExt<S>: DioxusRouterFnExt<S> {
/// # Example
/// ```rust, no_run
/// # #![allow(non_snake_case)]
/// # use dioxus_lib::prelude::*;
/// # use dioxus_server::prelude::*;
/// # use dioxus::prelude::*;
/// use dioxus_server::{DioxusRouterExt, DioxusRouterFnExt};
///
/// #[tokio::main]
@@ -52,9 +51,8 @@ pub trait DioxusRouterExt<S>: DioxusRouterFnExt<S> {
/// # Example
/// ```rust, no_run
/// # #![allow(non_snake_case)]
/// # use dioxus_lib::prelude::*;
/// # use dioxus_server::prelude::*;
/// use dioxus_server::{DioxusRouterExt, DioxusRouterFnExt};
/// # use dioxus::prelude::*;
/// use dioxus_server::{DioxusRouterExt, DioxusRouterFnExt, ServeConfig};
///
/// #[tokio::main]
/// async fn main() {
@@ -113,8 +111,8 @@ pub trait DioxusRouterFnExt<S> {
///
/// # Example
/// ```rust, no_run
/// # use dioxus_lib::prelude::*;
/// # use dioxus_server::prelude::*;
/// # use dioxus::prelude::*;
/// # use dioxus_server::DioxusRouterFnExt;
/// #[tokio::main]
/// async fn main() {
/// let addr = dioxus::cli_config::fullstack_address_or_localhost();
@@ -138,8 +136,8 @@ pub trait DioxusRouterFnExt<S> {
///
/// # Example
/// ```rust, no_run
/// # use dioxus_lib::prelude::*;
/// # use dioxus_server::prelude::*;
/// # use dioxus::prelude::*;
/// # use dioxus_server::DioxusRouterFnExt;
/// # use std::sync::Arc;
/// #[tokio::main]
/// async fn main() {
@@ -162,9 +160,8 @@ pub trait DioxusRouterFnExt<S> {
///
/// # Example
/// ```rust, no_run
/// # use dioxus_lib::prelude::*;
/// # use dioxus_server::prelude::*;
/// # use dioxus_server::prelude::*;
/// # use dioxus::prelude::*;
/// # use dioxus_server::{DioxusRouterFnExt, ServeConfig};
/// #[tokio::main]
/// async fn main() {
/// let router = axum::Router::new()