|
3 жил өмнө | |
---|---|---|
.vscode | 3 жил өмнө | |
docs | 3 жил өмнө | |
examples | 3 жил өмнө | |
notes | 4 жил өмнө | |
packages | 3 жил өмнө | |
src | 4 жил өмнө | |
.gitignore | 4 жил өмнө | |
Cargo.toml | 3 жил өмнө | |
LICENSE | 4 жил өмнө | |
README.md | 3 жил өмнө |
Frontend that scales.
Dioxus is a portable, performant, and ergonomic framework for building cross-platform user experiences in Rust.
fn App(cx: Context<()>) -> DomTree {
let mut count = use_state(cx, || 0);
cx.render(rsx! {
h1 { "High-Five counter: {count}" }
button { onclick: move |_| count += 1, "Up high!" }
button { onclick: move |_| count -= 1, "Down low!" }
})
};
Dioxus can be used to deliver webapps, desktop apps, static pages, liveview apps, eventually mobile apps (WIP), and more. At its core, Dioxus is entirely renderer agnostic and has great documentation for creating new renderers for any platform.
If you know React, then you already know Dioxus.
Web | Desktop | Mobile | State | Docs | Tools |
---|---|---|---|---|---|
Feature | Dioxus | React | Notes for Dioxus |
---|---|---|---|
Conditional Rendering | ✅ | ✅ | if/then to hide/show component |
Map, Iterator | ✅ | ✅ | map/filter/reduce to produce rsx! |
Keyed Components | ✅ | ✅ | advanced diffing with keys |
Web | ✅ | ✅ | renderer for web browser |
Desktop (webview) | ✅ | ✅ | renderer for desktop |
Shared State (Context) | ✅ | ✅ | share state through the tree |
Hooks | ✅ | ✅ | memory cells in components |
SSR | ✅ | ✅ | render directly to string |
Component Children | ✅ | ✅ | cx.children() as a list of nodes |
Headless components | ✅ | ✅ | components that don't return real elements |
Fragments | ✅ | ✅ | multiple elements without a real root |
Manual Props | ✅ | ✅ | Manually pass in props with spread syntax |
Controlled Inputs | ✅ | ✅ | stateful wrappers around inputs |
CSS/Inline Styles | ✅ | ✅ | syntax for inline styles/attribute groups |
Custom elements | ✅ | ✅ | Define new element primitives |
Suspense | ✅ | ✅ | schedule future render from future/promise |
Integrated error handling | ✅ | ✅ | Gracefully handle errors with ? syntax |
NodeRef | ✅ | ✅ | gain direct access to nodes |
Re-hydration | ✅ | ✅ | Pre-render to HTML to speed up first contentful paint |
Jank-Free Rendering | ✅ | ✅ | Large diffs are segmented across frames for silky-smooth transitions |
Cooperative Scheduling | ✅ | ✅ | Prioritize important events over non-important events |
Runs natively | ✅ | ❓ | runs as a portable binary w/o a runtime (Node) |
1st class global state | ✅ | ❓ | redux/recoil/mobx on top of context |
Subtree Memoization | ✅ | ❓ | skip diffing static element subtrees |
Compile-time correct | ✅ | ❓ | Throw errors on invalid template layouts |
Heuristic Engine | ✅ | ❓ | track component memory usage to minimize future allocations |
Fine-grained reactivity | 🛠 | ❓ | Skip diffing for fine-grain updates |
Effects | 🛠 | ✅ | Run effects after a component has been committed to render |
Feature | Dioxus | React | Notes for Dioxus |
---|---|---|---|
1st class router | 👀 | ✅ | Hook built on top of history |
Assets | 👀 | ✅ | include css/svg/img url statically |
Integrated classnames | 🛠 | ❓ | built-in classnames |
Transition | 👀 | 🛠 | High-level control over suspense |
Animation | 👀 | ✅ | Spring-style animations |
Native Mobile | 👀 | ✅ | Render with cacao |
Native Desktop | 👀 | ✅ | Render with native desktop |
3D Renderer | 👀 | ✅ | react-three-fiber |
Feature | Dioxus | React | Notes for Dioxus |
---|---|---|---|
Portal | ❓ | ✅ | cast elements through tree |
Error/Panic boundary | 👀 | ✅ | catch panics and display custom BSOD |
Code-splitting | 👀 | ✅ | Make bundle smaller/lazy |
LiveView | 👀 | ❓ | Example for SSR + WASM apps |
Remember: Dioxus is a library - not a compiler like Svelte. Plus, the inner VirtualDOM allows Dioxus to easily port into different runtimes, support SSR, and run remotely in the cloud. VDOMs tend to more ergonomic to work with and feel roughly like natural Rust code. The overhead of Dioxus is extraordinarily minimal... sure, there may be some overhead but on an order of magnitude lower than the time required to actually update the page.
The overhead layer between WASM and JS APIs is extremely poorly understood. Rust web benchmarks typically suffer from differences in how Rust and JS cache strings. In Dioxus, we solve most of these issues and our JS Framework Benchmark actually beats the WASM Bindgen benchmark in many cases. Compared to a "pure vanilla JS" solution, Dioxus adds less than 5% of overhead and takes advantage of batched DOM manipulation.
WASM binary sizes are another poorly understood characteristic of Rust web apps. 50kb of WASM and 50kb of JS are not made equally. In JS, the code must be downloaded first and then JIT-ted. Just-in-time compiling 50kb of JavaScript takes some time which is why 50kb of JavaScript sounds like a lot! However, with WASM, the code is downloaded and JIT-ted simultaneously through the magic of streaming compilation. By the time the 50kb of Rust is finished downloading, it is already ready to go. Again, Dioxus beats out many benchmarks with time-to-interactivity.
For reference, Dioxus hello-world
gzipped clocks in at around 60kb.
There are plenty Rust Elm-like frameworks in the world - we were not interested in making another! Instead, we borrowed hooks from React. JS and Rust share many structural similarities, so if you're comfortable with React, then you'll be plenty comfortable with Dioxus.
The RSX
DSL is barely a DSL. Rustaceans will find the DSL very similar to simply assembling nested structs, but without the syntactical overhead of "Default" everywhere or having to jump through hoops with the builder pattern. Between RSX, HTML, the Raw Factory API, and the NodeBuilder syntax, there's plenty of options to choose from.
Dioxus builds as roughly as fast as a complex WebPack-TypeScript site. Compile times will be slower than an equivalent TypeScript site, but not unbearably slow. The WASM compiler backend for Rust is very fast. Iterating on small components is basically instant and larger apps takes a few seconds. In practice, the compiler guarantees of Rust balance out the rebuild times.
Currently, Dioxus uses your device's native WebView library to draw the page. None of your app code is actually running in the WebView thread, so you can access system resources instead of having to go through something like NodeJS. This means your app will use Safari on macOS/iOS, Edge (Chromium) on Windows, and whatever is the default Web Browser for Linux and Android. Because your code is compiled and running natively, performance is not a problem. You will have to use the various "Escape Hatches" to use browser-native APIs (like WebGL) and work around visual differences in how Safari and Chrome render the page.
In the future, we are interested in using Webrenderer to provide a fully native renderer without having to go through the system WebView library. In practice, Dioxus mobile and desktop are great for CRUD-style apps, but the ergonomic cross-platform APIs (GPS, Camera, etc) are not there yet.
You shouldn't use Dioxus if: