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

Leptos v0.6 (NOT the rewrite) #2158

Merged
merged 100 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from 83 commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
cadd217
Update integration with support for axum 0.7 (#2082)
dgsantana Dec 31, 2023
c7422cd
First commit, checkpoint for cyclical dependency error
benwis Dec 31, 2023
c9627bf
Setup folder structure as before. Got a cyclical dependency though
benwis Dec 31, 2023
2a5c855
It starts to compile!
benwis Dec 31, 2023
197edeb
Made some progress, started work on pavex integration as well
benwis Jan 2, 2024
d5b9e84
properly gate `inventory`
gbj Jan 3, 2024
8fae768
`FromStr`-based lightweight `ServerFnError` deserialization
gbj Jan 3, 2024
7d45e6b
clean up my mistake
gbj Jan 3, 2024
6a16859
fix rkyv
gbj Jan 3, 2024
9c25821
fix Actix implementation with middleware
gbj Jan 3, 2024
dd368a8
@ealmloff changes to reexport actix/axum
gbj Jan 3, 2024
2dbc589
cargo fmt
gbj Jan 3, 2024
dec17fc
fix server actions and server multi actions
gbj Jan 3, 2024
c3e3ce7
changes to get `todo_app_sqlite_axum` example working
gbj Jan 4, 2024
af62d2e
automatically include server function handler in `.leptos_router()`
gbj Jan 4, 2024
db4158f
clear up warnings
gbj Jan 4, 2024
60efaef
start Actix work
gbj Jan 4, 2024
e1a9856
more Actix work
gbj Jan 5, 2024
c8fbee1
finished Actix support?
gbj Jan 5, 2024
fd97e2e
Restore the previous full functionality of Form
gbj Jan 5, 2024
566df03
actually use server functions in `ActionForm`
gbj Jan 5, 2024
4e3f1c8
handle client-side and server-side redirects correctly (in Axum)
gbj Jan 6, 2024
5e6f440
set up redirects in Actix
gbj Jan 6, 2024
f53ac1a
remove unused var
gbj Jan 6, 2024
db1497b
set version, input, etc. correctly
gbj Jan 7, 2024
f6b95e4
make sure endpoint names begin with a /
gbj Jan 7, 2024
853c080
add missing server fn registration
gbj Jan 7, 2024
f6ce82c
Fixed tests for `server_fn` (#2167)
rakshith-ravi Jan 8, 2024
a1bd84f
feat: add `serde-lite` codec for server functions (#2168)
rakshith-ravi Jan 9, 2024
f5c007d
use server fns directly in ActionForm and MultiActionForm
gbj Jan 8, 2024
be084a5
remove list of magic identifiers, use rust-analyzer to help with impo…
gbj Jan 9, 2024
738eeef
chore: clear warnings
gbj Jan 9, 2024
6114802
allow type paths for input/output, and properly namespace built-in en…
gbj Jan 10, 2024
c7941f7
clippy
gbj Jan 10, 2024
7f532cd
update todo_app_sqlite_csrs
gbj Jan 10, 2024
2af0d3d
update session_auth_axum
gbj Jan 10, 2024
81fb516
missing makefiles
gbj Jan 10, 2024
6c8e704
smh
gbj Jan 10, 2024
a5cbfa0
remove viz integration (see #2177)
gbj Jan 11, 2024
8f07818
nicer formatting, remove cfg-if
gbj Jan 11, 2024
31b2b9e
remove explicit `handle_server_fns` in most cases because it's now in…
gbj Jan 11, 2024
1d1de4a
remove `cfg-if` from all examples
gbj Jan 11, 2024
0a9cdba
getting started on docs
gbj Jan 11, 2024
15b04a8
more docs
gbj Jan 12, 2024
def4be8
docs
gbj Jan 12, 2024
b0cdeab
remove old code
gbj Jan 12, 2024
9488114
docs
gbj Jan 12, 2024
cc6f65c
initial version of server action error handling without JS
gbj Jan 13, 2024
5e08253
get both client and server side working
gbj Jan 13, 2024
88fee24
support setting server URL on either platform
gbj Jan 13, 2024
1ad7ee8
generalize error redirect behavior across integrations
gbj Jan 14, 2024
13a2691
working on server fn example
gbj Jan 14, 2024
90ba352
working on Axum version
gbj Jan 14, 2024
06c478b
feature-gate the form redirect stuff, and clear old errors from query
gbj Jan 15, 2024
0571ebb
working on example
gbj Jan 15, 2024
1777a40
fix!: remove clone in `Cow<'static, str>` `IntoView` impl (#1946)
tqwewe Jan 15, 2024
4366d78
Update login example (CSR only) (#2155)
flosse Jan 15, 2024
35e8e74
get rkyv working and work on custom encoding example
gbj Jan 15, 2024
1f017a2
hm custom encodings have orphan rule issues
gbj Jan 15, 2024
7d114c7
file upload example
gbj Jan 15, 2024
4d602c2
example with custom errors
gbj Jan 16, 2024
9a5a102
add middleware to kitchen-sink example
gbj Jan 16, 2024
21f8085
add streaming/file watcher example
gbj Jan 16, 2024
6a8c26a
streaming example with filesystem watcher
gbj Jan 17, 2024
bb923b3
erroneous hyphen
gbj Jan 17, 2024
7a086ad
update version number
gbj Jan 17, 2024
047235e
clippy
gbj Jan 17, 2024
c7fac64
fix merge error
gbj Jan 17, 2024
8d23d51
add package metadata
gbj Jan 17, 2024
22b4537
fix version numbers
gbj Jan 17, 2024
5065bed
example of middleware that can run before and/or after server fn
gbj Jan 17, 2024
320179b
remove misleading warning
gbj Jan 18, 2024
c5bab09
partial support for streaming requests (doesn't actually work in the …
gbj Jan 18, 2024
33ad305
serde-lite support should be enabled directly on server_fn
gbj Jan 18, 2024
3f22906
fix warning
gbj Jan 19, 2024
0df5dfe
weak dependency on Cargo.toml
gbj Jan 19, 2024
a3a15f2
expose all fields of ServerFnTraitObj via methods
gbj Jan 19, 2024
2fa6010
share inventory collect across types
gbj Jan 19, 2024
e179db1
use `&[u8]` instead of `Bytes` for requests
gbj Jan 19, 2024
1407245
clean up docs (closes #2197)
gbj Jan 19, 2024
f9cd853
add missing PartialEq/Eq implementations on ServerFnError (closes #2198)
gbj Jan 19, 2024
94cb4c0
remove pavex work (now in `pavex` branch)
gbj Jan 19, 2024
25120c0
fix streaming requests and clarify in docs
gbj Jan 19, 2024
a519859
Revert "use `&[u8]` instead of `Bytes` for requests"
gbj Jan 19, 2024
2a9e502
fix rkyv deserialization
gbj Jan 19, 2024
fdd5765
clean up examples
gbj Jan 19, 2024
1b1e027
clean up examples
gbj Jan 19, 2024
46e7abf
allow custom req/res/client types
gbj Jan 19, 2024
26d9d75
cargo fmt
gbj Jan 19, 2024
ddda785
fix multipart support
gbj Jan 19, 2024
f19def9
clippy
gbj Jan 19, 2024
eb45d05
clippy
gbj Jan 19, 2024
70ec0c2
update sso example
gbj Jan 19, 2024
2092c40
missing derives
gbj Jan 19, 2024
b4a1d90
clean up for CI
gbj Jan 20, 2024
8df46fc
examples: use old Axum version of `hackernews_js_fetch` until support…
gbj Jan 20, 2024
40da1fe
clippy
gbj Jan 20, 2024
c88bfbe
tweak sets of features for CI
gbj Jan 20, 2024
39f5481
clean up in docs and rename Axum extract() to match Actix extract()
gbj Jan 20, 2024
567644d
clarify docs here
gbj Jan 20, 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
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ jobs:
[
integrations/actix,
integrations/axum,
integrations/viz,
integrations/utils,
leptos,
leptos_config,
Expand Down
29 changes: 14 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ members = [
# integrations
"integrations/actix",
"integrations/axum",
"integrations/viz",
"integrations/utils",

# libraries
Expand All @@ -26,22 +25,22 @@ members = [
exclude = ["benchmarks", "examples"]

[workspace.package]
version = "0.5.7"
version = "0.6.0-beta"

[workspace.dependencies]
leptos = { path = "./leptos", version = "0.5.7" }
leptos_dom = { path = "./leptos_dom", version = "0.5.7" }
leptos_hot_reload = { path = "./leptos_hot_reload", version = "0.5.7" }
leptos_macro = { path = "./leptos_macro", version = "0.5.7" }
leptos_reactive = { path = "./leptos_reactive", version = "0.5.7" }
leptos_server = { path = "./leptos_server", version = "0.5.7" }
server_fn = { path = "./server_fn", version = "0.5.7" }
server_fn_macro = { path = "./server_fn_macro", version = "0.5.7" }
server_fn_macro_default = { path = "./server_fn/server_fn_macro_default", version = "0.5.7" }
leptos_config = { path = "./leptos_config", version = "0.5.7" }
leptos_router = { path = "./router", version = "0.5.7" }
leptos_meta = { path = "./meta", version = "0.5.7" }
leptos_integration_utils = { path = "./integrations/utils", version = "0.5.7" }
leptos = { path = "./leptos", version = "0.6.0-beta" }
leptos_dom = { path = "./leptos_dom", version = "0.6.0-beta" }
leptos_hot_reload = { path = "./leptos_hot_reload", version = "0.6.0-beta" }
leptos_macro = { path = "./leptos_macro", version = "0.6.0-beta" }
leptos_reactive = { path = "./leptos_reactive", version = "0.6.0-beta" }
leptos_server = { path = "./leptos_server", version = "0.6.0-beta" }
server_fn = { path = "./server_fn", version = "0.6.0-beta" }
server_fn_macro = { path = "./server_fn_macro", version = "0.6.0-beta" }
server_fn_macro_default = { path = "./server_fn/server_fn_macro_default", version = "0.6" }
leptos_config = { path = "./leptos_config", version = "0.6.0-beta" }
leptos_router = { path = "./router", version = "0.6.0-beta" }
leptos_meta = { path = "./meta", version = "0.6.0-beta" }
leptos_integration_utils = { path = "./integrations/utils", version = "0.6.0-beta" }

[profile.release]
codegen-units = 1
Expand Down
2 changes: 1 addition & 1 deletion examples/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ CARGO_MAKE_CRATE_WORKSPACE_MEMBERS = [
"login_with_token_csr_only",
"parent_child",
"router",
"server_fns_axum",
"session_auth_axum",
"slots",
"ssr_modes",
Expand All @@ -32,7 +33,6 @@ CARGO_MAKE_CRATE_WORKSPACE_MEMBERS = [
"timer",
"todo_app_sqlite",
"todo_app_sqlite_axum",
"todo_app_sqlite_viz",
"todomvc",
]

Expand Down
90 changes: 90 additions & 0 deletions examples/action-form-error-handling/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
[package]
name = "action-form-error-handling"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
actix-files = { version = "0.6", optional = true }
actix-web = { version = "4", optional = true, features = ["macros"] }
console_error_panic_hook = "0.1"
cfg-if = "1"
http = { version = "0.2", optional = true }
leptos = { path = "../../leptos" }
leptos_meta = { path = "../../meta" }
leptos_actix = { path = "../../integrations/actix", optional = true }
leptos_router = { path = "../../router" }
wasm-bindgen = "0.2"
serde = { version = "1", features = ["derive"] }

[features]
csr = ["leptos/csr", "leptos_meta/csr", "leptos_router/csr"]
hydrate = ["leptos/hydrate", "leptos_meta/hydrate", "leptos_router/hydrate"]
ssr = [
"dep:actix-files",
"dep:actix-web",
"dep:leptos_actix",
"leptos/ssr",
"leptos_meta/ssr",
"leptos_router/ssr",
]

# Defines a size-optimized profile for the WASM bundle in release mode
[profile.wasm-release]
inherits = "release"
opt-level = 'z'
lto = true
codegen-units = 1
panic = "abort"

[package.metadata.leptos]
# The name used by wasm-bindgen/cargo-leptos for the JS/WASM bundle. Defaults to the crate name
output-name = "leptos_start"
# The site root folder is where cargo-leptos generate all output. WARNING: all content of this folder will be erased on a rebuild. Use it in your server setup.
site-root = "target/site"
# The site-root relative folder where all compiled output (JS, WASM and CSS) is written
# Defaults to pkg
site-pkg-dir = "pkg"
# [Optional] The source CSS file. If it ends with .sass or .scss then it will be compiled by dart-sass into CSS. The CSS is optimized by Lightning CSS before being written to <site-root>/<site-pkg>/app.css
style-file = "style/main.scss"
# The IP and port (ex: 127.0.0.1:3000) where the server serves the content. Use it in your server setup.
site-addr = "127.0.0.1:3000"
# The port to use for automatic reload monitoring
reload-port = 3001
# [Optional] Command to use when running end2end tests. It will run in the end2end dir.
# [Windows] for non-WSL use "npx.cmd playwright test"
# This binary name can be checked in Powershell with Get-Command npx
end2end-cmd = "npx playwright test"
end2end-dir = "end2end"
# The browserlist query used for optimizing the CSS.
browserquery = "defaults"
# Set by cargo-leptos watch when building with that tool. Controls whether autoreload JS will be included in the head
watch = false
# The environment Leptos will run in, usually either "DEV" or "PROD"
env = "DEV"
# The features to use when compiling the bin target
#
# Optional. Can be over-ridden with the command line parameter --bin-features
bin-features = ["ssr"]

# If the --no-default-features flag should be used when compiling the bin target
#
# Optional. Defaults to false.
bin-default-features = false

# The features to use when compiling the lib target
#
# Optional. Can be over-ridden with the command line parameter --lib-features
lib-features = ["hydrate"]

# If the --no-default-features flag should be used when compiling the lib target
#
# Optional. Defaults to false.
lib-default-features = false

# The profile to use for the lib target when compiling for release
#
# Optional. Defaults to "release".
lib-profile-release = "wasm-release"
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ extend = [

[env]

CLIENT_PROCESS_NAME = "todo_app_sqlite_viz"
CLIENT_PROCESS_NAME = "action_form_error_handling"
68 changes: 68 additions & 0 deletions examples/action-form-error-handling/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<picture>
<source srcset="https://raw.githubusercontent.com/leptos-rs/leptos/main/docs/logos/Leptos_logo_Solid_White.svg" media="(prefers-color-scheme: dark)">
<img src="https://raw.githubusercontent.com/leptos-rs/leptos/main/docs/logos/Leptos_logo_RGB.svg" alt="Leptos Logo">
</picture>

# Leptos Starter Template

This is a template for use with the [Leptos](https://github.com/leptos-rs/leptos) web framework and the [cargo-leptos](https://github.com/akesson/cargo-leptos) tool.

## Creating your template repo

If you don't have `cargo-leptos` installed you can install it with

`cargo install cargo-leptos`

Then run

`cargo leptos new --git leptos-rs/start`

to generate a new project template (you will be prompted to enter a project name).

`cd {projectname}`

to go to your newly created project.

Of course, you should explore around the project structure, but the best place to start with your application code is in `src/app.rs`.

## Running your project

`cargo leptos watch`
By default, you can access your local project at `http://localhost:3000`

## Installing Additional Tools

By default, `cargo-leptos` uses `nightly` Rust, `cargo-generate`, and `sass`. If you run into any trouble, you may need to install one or more of these tools.

1. `rustup toolchain install nightly --allow-downgrade` - make sure you have Rust nightly
2. `rustup target add wasm32-unknown-unknown` - add the ability to compile Rust to WebAssembly
3. `cargo install cargo-generate` - install `cargo-generate` binary (should be installed automatically in future)
4. `npm install -g sass` - install `dart-sass` (should be optional in future)

## Executing a Server on a Remote Machine Without the Toolchain
After running a `cargo leptos build --release` the minimum files needed are:

1. The server binary located in `target/server/release`
2. The `site` directory and all files within located in `target/site`

Copy these files to your remote server. The directory structure should be:
```text
leptos_start
site/
```
Set the following environment variables (updating for your project as needed):
```sh
export LEPTOS_OUTPUT_NAME="leptos_start"
export LEPTOS_SITE_ROOT="site"
export LEPTOS_SITE_PKG_DIR="pkg"
export LEPTOS_SITE_ADDR="127.0.0.1:3000"
export LEPTOS_RELOAD_PORT="3001"
```
Finally, run the server binary.

## Notes about CSR and Trunk:
Although it is not recommended, you can also run your project without server integration using the feature `csr` and `trunk serve`:

`trunk serve --open --features csr`

This may be useful for integrating external tools which require a static site, e.g. `tauri`.
90 changes: 90 additions & 0 deletions examples/action-form-error-handling/src/app.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use leptos::*;
use leptos_meta::*;
use leptos_router::*;

#[component]
pub fn App() -> impl IntoView {
// Provides context that manages stylesheets, titles, meta tags, etc.
provide_meta_context();

view! {
// injects a stylesheet into the document <head>
// id=leptos means cargo-leptos will hot-reload this stylesheet
<Stylesheet id="leptos" href="/pkg/leptos_start.css"/>

// sets the document title
<Title text="Welcome to Leptos"/>

// content for this welcome page
<Router>
<main id="app">
<Routes>
<Route path="" view=HomePage/>
<Route path="/*any" view=NotFound/>
</Routes>
</main>
</Router>
}
}

#[server]
async fn do_something(should_error: Option<String>) -> Result<String, ServerFnError> {
if should_error.is_none() {
Ok(String::from("Successful submit"))
} else {
Err(ServerFnError::ServerError(String::from(
"You got an error!",
)))
}
}

/// Renders the home page of your application.
#[component]
fn HomePage() -> impl IntoView {
let do_something_action = Action::<DoSomething, _>::server();
let value = Signal::derive(move || do_something_action.value().get().unwrap_or_else(|| Ok(String::new())));

Effect::new_isomorphic(move |_| {
logging::log!("Got value = {:?}", value.get());
});

view! {
<h1>"Test the action form!"</h1>
<ErrorBoundary fallback=move |error| format!("{:#?}", error
.get()
.into_iter()
.next()
.unwrap()
.1.into_inner()
.to_string())
>
{value}
<ActionForm action=do_something_action class="form">
<label>Should error: <input type="checkbox" name="should_error"/></label>
<button type="submit">Submit</button>
</ActionForm>
</ErrorBoundary>
}
}

/// 404 - Not Found
#[component]
fn NotFound() -> impl IntoView {
// set an HTTP status code 404
// this is feature gated because it can only be done during
// initial server-side rendering
// if you navigate to the 404 page subsequently, the status
// code will not be set because there is not a new HTTP request
// to the server
#[cfg(feature = "ssr")]
{
// this can be done inline because it's synchronous
// if it were async, we'd use a server function
let resp = expect_context::<leptos_actix::ResponseOptions>();
resp.set_status(actix_web::http::StatusCode::NOT_FOUND);
}

view! {
<h1>"Not Found"</h1>
}
}
18 changes: 18 additions & 0 deletions examples/action-form-error-handling/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
pub mod app;
use cfg_if::cfg_if;

cfg_if! {
if #[cfg(feature = "hydrate")] {

use wasm_bindgen::prelude::wasm_bindgen;

#[wasm_bindgen]
pub fn hydrate() {
use app::*;

console_error_panic_hook::set_once();

leptos::mount_to_body(App);
}
}
}
53 changes: 53 additions & 0 deletions examples/action-form-error-handling/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#[cfg(feature = "ssr")]
#[actix_web::main]
async fn main() -> std::io::Result<()> {
use actix_files::Files;
use actix_web::*;
use leptos::*;
use leptos_actix::{generate_route_list, LeptosRoutes};
use action_form_error_handling::app::*;

let conf = get_configuration(None).await.unwrap();
let addr = conf.leptos_options.site_addr;
// Generate the list of routes in your Leptos App
let routes = generate_route_list(App);
println!("listening on http://{}", &addr);

HttpServer::new(move || {
let leptos_options = &conf.leptos_options;
let site_root = &leptos_options.site_root;

App::new()
.route("/api/{tail:.*}", leptos_actix::handle_server_fns())
// serve JS/WASM/CSS from `pkg`
.service(Files::new("/pkg", format!("{site_root}/pkg")))
.leptos_routes(leptos_options.to_owned(), routes.to_owned(), App)
.app_data(web::Data::new(leptos_options.to_owned()))
//.wrap(middleware::Compress::default())
})
.bind(&addr)?
.run()
.await
}

#[cfg(not(any(feature = "ssr", feature = "csr")))]
pub fn main() {
// no client-side main function
// unless we want this to work with e.g., Trunk for pure client-side testing
// see lib.rs for hydration function instead
// see optional feature `csr` instead
}

#[cfg(all(not(feature = "ssr"), feature = "csr"))]
pub fn main() {
// a client-side main function is required for using `trunk serve`
// prefer using `cargo leptos serve` instead
// to run: `trunk serve --open --features csr`
use leptos::*;
use action_form_error_handling::app::*;
use wasm_bindgen::prelude::wasm_bindgen;

console_error_panic_hook::set_once();

leptos::mount_to_body(App);
}
Loading
Loading