leptos-rs / start-axum Goto Github PK
View Code? Open in Web Editor NEWStarter template for use with the Leptos web framework and Axum.
License: The Unlicense
Starter template for use with the Leptos web framework and Axum.
License: The Unlicense
I am experiencing difficulties with the start-axum project template when creating a new project using it as a template. Upon running the project with the command cargo run --features ssr, the expected behavior is that the project should function properly. Specifically, when clicking the "Click Me" button, the counter should increment by 1. However, the counter does not respond as expected.
Create a new project using the start-axum project template.
Run the project using the command: cargo run --features ssr.
Open the project in a web browser.
Click the "Click Me" button and observe the counter behavior.
The counter should increment by 1 when the "Click Me" button is pressed.
The project should display the necessary files (js, css, wasm) without any 404 errors.
The counter does not respond as expected.
Browser console shows 404 errors for js, css, and wasm files.
This happens when running cargo test --profile release --package start-axum
from inside the nix shell (using rust nightly):
Doc-tests start-axum
error[E0433]: failed to resolve: use of undeclared crate or module `tracing`
--> src/error_template.rs:25:1
|
25 | #[component]
| ^^^^^^^^^^^^ use of undeclared crate or module `tracing`
|
= note: this error originates in the attribute macro `::leptos::leptos_dom::tracing::instrument` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0433]: failed to resolve: use of undeclared crate or module `tracing`
When some error occurs, SSR sends ErrorTemplate
component while CSR always trys to render App
. This leads to hydration bugs and you can see error messages like below in DevTools:
panicked at D:\data\cargo\registry\src\index.crates.io-6f17d22bba15001f\leptos_dom-0.4.8\src\html.rs:1265:13:
assertion failed: `(left == right)`
left: `"H1"`,
right: `"LINK"`: SSR and CSR elements have the same hydration key but different node kinds. Check out the docs for information about this kind of hydration bug: https://leptos-rs.github.io/leptos/ssr/24_hydration_bugs.html
start-axum/src/error_template.rs
Lines 28 to 29 in 182477f
I can't find a reason why this requires two separate arguments. Using a single (non-optional) argument works just fine:
diff --git a/src/app.rs b/src/app.rs
index 5a5aff9..fe2814f 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -22,8 +22,9 @@ pub fn App(cx: Scope) -> impl IntoView {
<Router fallback=|cx| {
let mut outside_errors = Errors::default();
outside_errors.insert_with_default_key(AppError::NotFound);
+ let errors = create_rw_signal(cx, outside_errors);
view! { cx,
- <ErrorTemplate outside_errors/>
+ <ErrorTemplate errors/>
}
.into_view(cx)
}>
diff --git a/src/error_template.rs b/src/error_template.rs
index 3a947fa..1ad6c42 100644
--- a/src/error_template.rs
+++ b/src/error_template.rs
@@ -25,16 +25,8 @@ impl AppError {
#[component]
pub fn ErrorTemplate(
cx: Scope,
- #[prop(optional)] outside_errors: Option<Errors>,
- #[prop(optional)] errors: Option<RwSignal<Errors>>,
+ errors: RwSignal<Errors>
) -> impl IntoView {
- let errors = match outside_errors {
- Some(e) => create_rw_signal(cx, e),
- None => match errors {
- Some(e) => e,
- None => panic!("No Errors found and we expected errors!"),
- },
- };
// Get Errors from Signal
let errors = errors.get();
I have downloaded start-axum
template today and executed setup all commands listed in README
file but after that while running cargo leptos watch
I get following errors and the app doesn’t show up in the browser:
leptos-axum git:(main) ✗ cargo leptos watch
Compiling leptos_dom v0.5.2
error[E0609]: no field `children` on type `html::HtmlElement<El>`
--> /Users/mateusz.kwiatkowski/.cargo/registry/src/index.crates.io-6f17d22bba15001f/leptos_dom-0.5.2/src/html.rs:593:30
|
593 | if matches!(self.children, ElementChildren::Chunks(_)) {
| ^^^^^^^^ unknown field
|
= note: available fields are: `span`, `element`, `view_marker`
error[E0609]: no field `children` on type `html::HtmlElement<El>`
--> /Users/mateusz.kwiatkowski/.cargo/registry/src/index.crates.io-6f17d22bba15001f/leptos_dom-0.5.2/src/html.rs:676:30
|
676 | if matches!(self.children, ElementChildren::Chunks(_)) {
| ^^^^^^^^ unknown field
|
= note: available fields are: `span`, `element`, `view_marker`
error[E0609]: no field `children` on type `html::HtmlElement<El>`
--> /Users/mateusz.kwiatkowski/.cargo/registry/src/index.crates.io-6f17d22bba15001f/leptos_dom-0.5.2/src/html.rs:740:30
|
740 | if matches!(self.children, ElementChildren::Chunks(_)) {
| ^^^^^^^^ unknown field
|
= note: available fields are: `span`, `element`, `view_marker`
error[E0609]: no field `children` on type `html::HtmlElement<El>`
--> /Users/mateusz.kwiatkowski/.cargo/registry/src/index.crates.io-6f17d22bba15001f/leptos_dom-0.5.2/src/html.rs:767:30
|
767 | if matches!(self.children, ElementChildren::Chunks(_)) {
| ^^^^^^^^ unknown field
|
= note: available fields are: `span`, `element`, `view_marker`
error[E0609]: no field `children` on type `html::HtmlElement<El>`
--> /Users/mateusz.kwiatkowski/.cargo/registry/src/index.crates.io-6f17d22bba15001f/leptos_dom-0.5.2/src/html.rs:882:30
|
882 | if matches!(self.children, ElementChildren::Chunks(_)) {
| ^^^^^^^^ unknown field
|
= note: available fields are: `span`, `element`, `view_marker`
error[E0433]: failed to resolve: use of undeclared type `ElementChildren`
--> /Users/mateusz.kwiatkowski/.cargo/registry/src/index.crates.io-6f17d22bba15001f/leptos_dom-0.5.2/src/html.rs:593:40
|
593 | if matches!(self.children, ElementChildren::Chunks(_)) {
| ^^^^^^^^^^^^^^^ use of undeclared type `ElementChildren`
error[E0433]: failed to resolve: use of undeclared type `ElementChildren`
--> /Users/mateusz.kwiatkowski/.cargo/registry/src/index.crates.io-6f17d22bba15001f/leptos_dom-0.5.2/src/html.rs:676:40
|
676 | if matches!(self.children, ElementChildren::Chunks(_)) {
| ^^^^^^^^^^^^^^^ use of undeclared type `ElementChildren`
error[E0433]: failed to resolve: use of undeclared type `ElementChildren`
--> /Users/mateusz.kwiatkowski/.cargo/registry/src/index.crates.io-6f17d22bba15001f/leptos_dom-0.5.2/src/html.rs:740:40
|
740 | if matches!(self.children, ElementChildren::Chunks(_)) {
| ^^^^^^^^^^^^^^^ use of undeclared type `ElementChildren`
error[E0433]: failed to resolve: use of undeclared type `ElementChildren`
--> /Users/mateusz.kwiatkowski/.cargo/registry/src/index.crates.io-6f17d22bba15001f/leptos_dom-0.5.2/src/html.rs:767:40
|
767 | if matches!(self.children, ElementChildren::Chunks(_)) {
| ^^^^^^^^^^^^^^^ use of undeclared type `ElementChildren`
error[E0433]: failed to resolve: use of undeclared type `ElementChildren`
--> /Users/mateusz.kwiatkowski/.cargo/registry/src/index.crates.io-6f17d22bba15001f/leptos_dom-0.5.2/src/html.rs:882:40
|
882 | if matches!(self.children, ElementChildren::Chunks(_)) {
| ^^^^^^^^^^^^^^^ use of undeclared type `ElementChildren`
Some errors have detailed explanations: E0433, E0609.
For more information about an error, try `rustc --explain E0433`.
error: could not compile `leptos_dom` (lib) due to 10 previous errors
Notify watching paths public, style, src
On the other hand start-axum-workspace
works fine and compiles without errors.
Whenever, I try to add
sqlx = { version = "*", features = ["runtime-tokio-rustls", "sqlite", "json"] }
to Cargo.toml
I get lots of compile errors like below.
I have tried to used different versions but running out of ideas.
Thanks
error[E0432]: unresolved import `crate::sys::IoSourceState`
--> /home/glenn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.9/src/io_source.rs:12:5
|
12 | use crate::sys::IoSourceState;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ no `IoSourceState` in `sys`
error[E0432]: unresolved import `crate::sys::tcp`
--> /home/glenn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.9/src/net/tcp/listener.rs:15:17
|
15 | use crate::sys::tcp::{bind, listen, new_for_addr};
| ^^^ could not find `tcp` in `sys`
error[E0432]: unresolved import `crate::sys::tcp`
--> /home/glenn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.9/src/net/tcp/stream.rs:13:17
|
13 | use crate::sys::tcp::{connect, new_for_addr};
| ^^^ could not find `tcp` in `sys`
error[E0433]: failed to resolve: could not find `Selector` in `sys`
--> /home/glenn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.9/src/poll.rs:308:18
|
308 | sys::Selector::new().map(|selector| Poll {
| ^^^^^^^^ could not find `Selector` in `sys`
error[E0433]: failed to resolve: could not find `event` in `sys`
--> /home/glenn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.9/src/event/event.rs:24:14
|
24 | sys::event::token(&self.inner)
| ^^^^^ could not find `event` in `sys`
error[E0433]: failed to resolve: could not find `event` in `sys`
--> /home/glenn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.9/src/event/event.rs:38:14
|
38 | sys::event::is_readable(&self.inner)
| ^^^^^ could not find `event` in `sys`
error[E0433]: failed to resolve: could not find `event` in `sys`
--> /home/glenn/.cargo/registry/src/index.crates.io-6f17d22bba15001f/mio-0.8.9/src/event/event.rs:43:14
|
43 | sys::event::is_writable(&self.inner)
| ^^^^^ could not find `event` in `sys`
Please create a branch that allows using the stable features for leptos, leptos_meta, and leptos_router.
https://github.com/lalanikarim/start-axum/tree/stable
I believe this module can be removed entirely, and main.rs
can instead use fallback_service
in its place, a. la:
let client_dist = ServeDir::new(leptos_options.site_root.clone());
...
let app = Router::new()
...
.fallback_service(client_dist)
In context: https://github.com/srid/leptos-fullstack/blob/0639b5909d61701c2bbdbb34fe831d574af06efe/src/server.rs#L17-L22
This will also (positively?) change the behaviour of the program as it will now cause 404, as one would expect, on missing requests (instead of falling back to serving the app).
I can't see what is reacting to this value or when it would be set to "PROD". Is it only read for certain deployment solutions?
I'm new to Rust and trying to learn Leptos. I started installing cargo-leptos
.
A project was generated using below
cargo leptos new --git leptos-rs/start-axum
.
├── Cargo.lock
├── Cargo.toml
├── end2end
│ ├── package.json
│ ├── package-lock.json
│ ├── playwright.config.ts
│ └── tests
│ └── example.spec.ts
├── LICENSE
├── public
│ └── favicon.ico
├── README.md
├── rust-toolchain.toml
├── src
│ ├── app.rs
│ ├── error_template.rs
│ ├── fileserv.rs
│ ├── lib.rs
│ └── main.rs
├── style
│ └── main.scss
When watching the project, I get thousands of lines of errors from the core Rust. First I tried it in NixOS 23
directly installing cargo-leptos
from the package manager but I got the same issue so I created a custom docker container to check if it's a NixOS
related issue. It appears not.
cargo leptos watch
info: syncing channel updates for 'nightly-x86_64-unknown-linux-gnu'
info: latest update on 2023-09-17, rust version 1.74.0-nightly (7d9bce327 2023-09-16)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
info: installing component 'rust-std'
info: installing component 'rustc'
info: installing component 'rustfmt'
Compiling proc-macro2 v1.0.67
Compiling unicode-ident v1.0.12
Compiling version_check v0.9.4
Compiling once_cell v1.18.0
Compiling autocfg v1.1.0
Compiling thiserror v1.0.48
Compiling serde v1.0.188
Compiling wasm-bindgen-shared v0.2.87
Compiling cfg-if v1.0.0
Compiling syn v1.0.109
Compiling bumpalo v3.14.0
Compiling log v0.4.20
Compiling wasm-bindgen v0.2.87
Compiling memchr v2.6.3
Compiling itoa v1.0.9
Compiling futures-core v0.3.28
Compiling serde_json v1.0.107
Compiling futures-channel v0.3.28
Compiling libc v0.2.148
Compiling ryu v1.0.15
Compiling unicode-xid v0.2.4
Compiling futures-sink v0.3.28
Compiling futures-task v0.3.28
Compiling smallvec v1.11.0
Compiling pin-project-lite v0.2.13
Compiling futures-util v0.3.28
Compiling lazy_static v1.4.0
Compiling ucd-trie v0.1.6
error[E0463]: can't find crate for `core`
|
= note: the `wasm32-unknown-unknown` target may not be installed
= help: consider downloading the target with `rustup target add wasm32-unknown-unknown`
= help: consider building the standard library from source with `cargo build -Zbuild-std`
error[E0463]: can't find crate for `compiler_builtins`
error[E0463]: can't find crate for `core`
--> /home/s1n7ax/.cargo/registry/src/index.crates.io-6f17d22bba15001f/itoa-1.0.9/src/lib.rs:45:5
|
45 | use core::mem::{self, MaybeUninit};
| ^^^^ can't find crate
|
= note: the `wasm32-unknown-unknown` target may not be installed
Is it my editor config or is it a thing? can I do anything about it?
After I added serde with:
cargo add serde --features derive
I get and error on safari and the Click Me button is no longer responding. With Chrome its working.
Any ideas?
Using nightly as default might not be good for all environments, maybe switch to per project configuration. This template only compiles on nightly:
error[E0554]: `#![feature]` may not be used on the stable release channel
--> ~/.cargo/registry/src/github.com-1ecc6299db9ec823/server_fn_macro-0.2.5/src/lib.rs:1:46
|
1 | #![cfg_attr(not(feature = "stable"), feature(proc_macro_span))]
|
Similar issue like #24 but with a different error message. Maybe it is related to a Mac M1.
It didn't work with the start-axum-workspace
sample as mentioned in #24
The source can also be found here: https://github.com/photos-network/frontend/tree/leptos-rewrite
➜ frontend git:(leptos-rewrite) rustc -vV
rustc 1.74.0 (79e9716c9 2023-11-13) (Homebrew)
binary: rustc
commit-hash: 79e9716c980570bfd1f666e3b16ac583f0168962
commit-date: 2023-11-13
host: aarch64-apple-darwin
release: 1.74.0
LLVM version: 17.0.5
➜ frontend git:(leptos-rewrite) cargo leptos new --git leptos-rs/start-axum
🤷 Project Name: frontend
🔧 Destination: /Users/stuermer/workspace/photos-network/frontend/frontend ...
🔧 project-name: frontend ...
🔧 Generating template ...
🔧 Moving generated files into: `/Users/stuermer/workspace/photos-network/frontend/frontend`...
🔧 Initializing a fresh Git repository
✨ Done! New project created /Users/stuermer/workspace/photos-network/frontend/frontend
➜ frontend git:(leptos-rewrite) ✗ cd frontend
➜ frontend git:(leptos-rewrite) ✗ rustup toolchain list
stable-aarch64-apple-darwin (default)
stable-x86_64-apple-darwin
nightly-aarch64-apple-darwin (override)
➜ frontend git:(leptos-rewrite) ✗ cargo leptos build
Compiling proc-macro2 v1.0.70
Compiling unicode-ident v1.0.12
Compiling version_check v0.9.4
Compiling once_cell v1.19.0
Compiling wasm-bindgen-shared v0.2.89
Compiling serde v1.0.193
Compiling bumpalo v3.14.0
Compiling log v0.4.20
Compiling wasm-bindgen v0.2.89
Compiling autocfg v1.1.0
Compiling thiserror v1.0.51
Compiling cfg-if v1.0.0
error[E0463]: can't find crate for `core`
|
= note: the `wasm32-unknown-unknown` target may not be installed
= help: consider downloading the target with `rustup target add wasm32-unknown-unknown`
error[E0463]: can't find crate for `compiler_builtins`
Compiling memchr v2.6.4
For more information about this error, try `rustc --explain E0463`.
error: could not compile `cfg-if` (lib) due to 2 previous errors
warning: build failed, waiting for other jobs to finish...
error[E0463]: can't find crate for `std`
--> /Users/stuermer/.cargo/registry/src/index.crates.io-6f17d22bba15001f/memchr-2.6.4/src/lib.rs:198:1
|
198 | extern crate std;
| ^^^^^^^^^^^^^^^^^ can't find crate
|
= note: the `wasm32-unknown-unknown` target may not be installed
= help: consider downloading the target with `rustup target add wasm32-unknown-unknown`
error[E0463]: can't find crate for `alloc`
--> /Users/stuermer/.cargo/registry/src/index.crates.io-6f17d22bba15001f/memchr-2.6.4/src/lib.rs:201:1
|
201 | extern crate alloc;
| ^^^^^^^^^^^^^^^^^^^ can't find crate
error[E0463]: can't find crate for `core`
--> /Users/stuermer/.cargo/registry/src/index.crates.io-6f17d22bba15001f/memchr-2.6.4/src/vector.rs:469:9
|
469 | use core::arch::wasm32::*;
| ^^^^ can't find crate
|
= note: the `wasm32-unknown-unknown` target may not be installed
= help: consider downloading the target with `rustup target add wasm32-unknown-unknown`
error[E0463]: can't find crate for `core`
--> /Users/stuermer/.cargo/registry/src/index.crates.io-6f17d22bba15001f/memchr-2.6.4/src/arch/all/twoway.rs:28:5
|
28 | use core::cmp;
| ^^^^ can't find crate
|
= note: the `wasm32-unknown-unknown` target may not be installed
= help: consider downloading the target with `rustup target add wasm32-unknown-unknown`
error[E0463]: can't find crate for `core`
--> /Users/stuermer/.cargo/registry/src/index.crates.io-6f17d22bba15001f/memchr-2.6.4/src/arch/wasm32/simd128/memchr.rs:23:5
|
23 | use core::arch::wasm32::v128;
| ^^^^ can't find crate
|
= note: the `wasm32-unknown-unknown` target may not be installed
= help: consider downloading the target with `rustup target add wasm32-unknown-unknown`
error[E0463]: can't find crate for `core`
--> /Users/stuermer/.cargo/registry/src/index.crates.io-6f17d22bba15001f/memchr-2.6.4/src/arch/wasm32/simd128/packedpair.rs:11:5
|
11 | use core::arch::wasm32::v128;
| ^^^^ can't find crate
|
= note: the `wasm32-unknown-unknown` target may not be installed
= help: consider downloading the target with `rustup target add wasm32-unknown-unknown`
error[E0463]: can't find crate for `core`
--> /Users/stuermer/.cargo/registry/src/index.crates.io-6f17d22bba15001f/memchr-2.6.4/src/cow.rs:1:5
|
1 | use core::ops;
| ^^^^ can't find crate
|
= note: the `wasm32-unknown-unknown` target may not be installed
= help: consider downloading the target with `rustup target add wasm32-unknown-unknown`
profile.wasm-release
inherits from release
but profile.release
is not set.
Wouldn't be Cargo.toml
look like this instead?
[profile.release]
lto = true # Enable link-time optimization
codegen-units = 1 # Reduce number of codegen units to increase optimizations
panic = "abort" # Abort on panic
strip = true # Strip symbols from binary
# Defines a size-optimized profile for the WASM bundle in release mode
[profile.wasm-release]
inherits = "release"
opt-level = "z" # Optimize for size
It allows to have start-axum
from 9MB to 4.1MB on my M1.
strip=true
will be also very useful for linux users as the debug symbols are embedded in the binary, unlike on Windows or Mac. And it's also MB of data.
Currently when requesting a file which is not available the 404 page is blank.
This is due to error_template
being called with None
.
Relevant lines in fileserv.rs:
https://github.com/Indrazar/start-axum/blob/main/src/fileserv.rs#L25
https://github.com/Indrazar/start-axum/blob/main/src/fileserv.rs#L30
I seem to get the following error on my project. Very frustrating. Can anyone point me in the right direction?
self.inner.deregister(registry)
| ^^^^^^^^^^ method not found in IoSource<UdpSocket>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.