Fix #1938, allow explicit props

This commit is contained in:
Jonathan Kelley 2024-03-18 15:34:46 -07:00
parent f266213618
commit 9c64fc4769
No known key found for this signature in database
GPG key ID: 1FBB50F7EB0A08BE
4 changed files with 73 additions and 44 deletions

85
Cargo.lock generated
View file

@ -1951,11 +1951,11 @@ dependencies = [
[[package]] [[package]]
name = "dioxus" name = "dioxus"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"criterion 0.3.6", "criterion 0.3.6",
"dioxus-config-macro", "dioxus-config-macro",
"dioxus-core 0.5.0-alpha.1", "dioxus-core 0.5.0-alpha.2",
"dioxus-core-macro", "dioxus-core-macro",
"dioxus-desktop", "dioxus-desktop",
"dioxus-fullstack", "dioxus-fullstack",
@ -1979,7 +1979,7 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-autofmt" name = "dioxus-autofmt"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"dioxus-rsx", "dioxus-rsx",
"prettier-please", "prettier-please",
@ -1992,7 +1992,7 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-check" name = "dioxus-check"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"indoc", "indoc",
"owo-colors", "owo-colors",
@ -2004,7 +2004,7 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-cli" name = "dioxus-cli"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"atty", "atty",
@ -2021,7 +2021,7 @@ dependencies = [
"dioxus-autofmt", "dioxus-autofmt",
"dioxus-check", "dioxus-check",
"dioxus-cli-config", "dioxus-cli-config",
"dioxus-core 0.5.0-alpha.1", "dioxus-core 0.5.0-alpha.2",
"dioxus-hot-reload", "dioxus-hot-reload",
"dioxus-html", "dioxus-html",
"dioxus-rsx", "dioxus-rsx",
@ -2069,7 +2069,7 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-cli-config" name = "dioxus-cli-config"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"cargo_toml 0.18.0", "cargo_toml 0.18.0",
"clap 4.4.18", "clap 4.4.18",
@ -2084,7 +2084,7 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-config-macro" name = "dioxus-config-macro"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -2106,7 +2106,7 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-core" name = "dioxus-core"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"dioxus", "dioxus",
"dioxus-ssr", "dioxus-ssr",
@ -2127,7 +2127,7 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-core-macro" name = "dioxus-core-macro"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"constcat", "constcat",
"convert_case 0.6.0", "convert_case 0.6.0",
@ -2149,13 +2149,13 @@ checksum = "2ea539174bb236e0e7dc9c12b19b88eae3cb574dedbd0252a2d43ea7e6de13e2"
[[package]] [[package]]
name = "dioxus-desktop" name = "dioxus-desktop"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"core-foundation", "core-foundation",
"dioxus", "dioxus",
"dioxus-cli-config", "dioxus-cli-config",
"dioxus-core 0.5.0-alpha.1", "dioxus-core 0.5.0-alpha.2",
"dioxus-hooks", "dioxus-hooks",
"dioxus-hot-reload", "dioxus-hot-reload",
"dioxus-html", "dioxus-html",
@ -2205,7 +2205,7 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-ext" name = "dioxus-ext"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"dioxus-autofmt", "dioxus-autofmt",
"html_parser", "html_parser",
@ -2215,7 +2215,7 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-fullstack" name = "dioxus-fullstack"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"anymap", "anymap",
"async-trait", "async-trait",
@ -2253,10 +2253,10 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-hooks" name = "dioxus-hooks"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"dioxus", "dioxus",
"dioxus-core 0.5.0-alpha.1", "dioxus-core 0.5.0-alpha.2",
"dioxus-debug-cell", "dioxus-debug-cell",
"dioxus-signals", "dioxus-signals",
"futures-channel", "futures-channel",
@ -2271,10 +2271,10 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-hot-reload" name = "dioxus-hot-reload"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"chrono", "chrono",
"dioxus-core 0.5.0-alpha.1", "dioxus-core 0.5.0-alpha.2",
"dioxus-html", "dioxus-html",
"dioxus-rsx", "dioxus-rsx",
"execute", "execute",
@ -2288,10 +2288,10 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-html" name = "dioxus-html"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"dioxus-core 0.5.0-alpha.1", "dioxus-core 0.5.0-alpha.2",
"dioxus-html-internal-macro", "dioxus-html-internal-macro",
"dioxus-rsx", "dioxus-rsx",
"enumset", "enumset",
@ -2311,7 +2311,7 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-html-internal-macro" name = "dioxus-html-internal-macro"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"convert_case 0.6.0", "convert_case 0.6.0",
"proc-macro2", "proc-macro2",
@ -2322,9 +2322,9 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-interpreter-js" name = "dioxus-interpreter-js"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"dioxus-core 0.5.0-alpha.1", "dioxus-core 0.5.0-alpha.2",
"dioxus-html", "dioxus-html",
"js-sys", "js-sys",
"md5", "md5",
@ -2337,10 +2337,10 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-lib" name = "dioxus-lib"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"dioxus-config-macro", "dioxus-config-macro",
"dioxus-core 0.5.0-alpha.1", "dioxus-core 0.5.0-alpha.2",
"dioxus-core-macro", "dioxus-core-macro",
"dioxus-hooks", "dioxus-hooks",
"dioxus-html", "dioxus-html",
@ -2350,12 +2350,12 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-liveview" name = "dioxus-liveview"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"axum", "axum",
"dioxus", "dioxus",
"dioxus-cli-config", "dioxus-cli-config",
"dioxus-core 0.5.0-alpha.1", "dioxus-core 0.5.0-alpha.2",
"dioxus-hot-reload", "dioxus-hot-reload",
"dioxus-html", "dioxus-html",
"dioxus-interpreter-js", "dioxus-interpreter-js",
@ -2377,7 +2377,7 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-mobile" name = "dioxus-mobile"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"dioxus-desktop", "dioxus-desktop",
] ]
@ -2423,15 +2423,17 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-router" name = "dioxus-router"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"axum", "axum",
"console_error_panic_hook",
"criterion 0.5.1", "criterion 0.5.1",
"dioxus", "dioxus",
"dioxus-cli-config", "dioxus-cli-config",
"dioxus-fullstack", "dioxus-fullstack",
"dioxus-lib", "dioxus-lib",
"dioxus-liveview", "dioxus-liveview",
"dioxus-router",
"dioxus-router-macro", "dioxus-router-macro",
"dioxus-ssr", "dioxus-ssr",
"gloo", "gloo",
@ -2444,12 +2446,13 @@ dependencies = [
"url", "url",
"urlencoding", "urlencoding",
"wasm-bindgen", "wasm-bindgen",
"wasm-bindgen-test",
"web-sys", "web-sys",
] ]
[[package]] [[package]]
name = "dioxus-router-macro" name = "dioxus-router-macro"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@ -2459,9 +2462,9 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-rsx" name = "dioxus-rsx"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"dioxus-core 0.5.0-alpha.1", "dioxus-core 0.5.0-alpha.2",
"internment", "internment",
"krates", "krates",
"proc-macro2", "proc-macro2",
@ -2473,10 +2476,10 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-signals" name = "dioxus-signals"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"dioxus", "dioxus",
"dioxus-core 0.5.0-alpha.1", "dioxus-core 0.5.0-alpha.2",
"futures-channel", "futures-channel",
"futures-util", "futures-util",
"generational-box", "generational-box",
@ -2492,7 +2495,7 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-ssr" name = "dioxus-ssr"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"argh", "argh",
@ -2500,7 +2503,7 @@ dependencies = [
"async-trait", "async-trait",
"chrono", "chrono",
"dioxus", "dioxus",
"dioxus-core 0.5.0-alpha.1", "dioxus-core 0.5.0-alpha.2",
"dioxus-html", "dioxus-html",
"dioxus-signals", "dioxus-signals",
"fern", "fern",
@ -2526,12 +2529,12 @@ dependencies = [
[[package]] [[package]]
name = "dioxus-web" name = "dioxus-web"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"console_error_panic_hook", "console_error_panic_hook",
"dioxus", "dioxus",
"dioxus-core 0.5.0-alpha.1", "dioxus-core 0.5.0-alpha.2",
"dioxus-html", "dioxus-html",
"dioxus-interpreter-js", "dioxus-interpreter-js",
"dioxus-ssr", "dioxus-ssr",
@ -2556,7 +2559,7 @@ dependencies = [
[[package]] [[package]]
name = "dioxus_server_macro" name = "dioxus_server_macro"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"convert_case 0.6.0", "convert_case 0.6.0",
"proc-macro2", "proc-macro2",
@ -3348,7 +3351,7 @@ dependencies = [
[[package]] [[package]]
name = "generational-box" name = "generational-box"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"criterion 0.3.6", "criterion 0.3.6",
"parking_lot", "parking_lot",
@ -7319,7 +7322,7 @@ dependencies = [
[[package]] [[package]]
name = "rsx-rosetta" name = "rsx-rosetta"
version = "0.5.0-alpha.1" version = "0.5.0-alpha.2"
dependencies = [ dependencies = [
"convert_case 0.5.0", "convert_case 0.5.0",
"dioxus-autofmt", "dioxus-autofmt",

View file

@ -14,7 +14,7 @@ fn main() {
fn app() -> Element { fn app() -> Element {
rsx! { rsx! {
spreadable_component { SpreadableComponent {
width: "10px", width: "10px",
extra_data: "hello{1}", extra_data: "hello{1}",
extra_data2: "hello{2}", extra_data2: "hello{2}",
@ -34,7 +34,8 @@ struct Props {
extra_data2: String, extra_data2: String,
} }
fn spreadable_component(props: Props) -> Element { #[component]
fn SpreadableComponent(props: Props) -> Element {
rsx! { rsx! {
audio { ..props.attributes, "1: {props.extra_data}\n2: {props.extra_data2}" } audio { ..props.attributes, "1: {props.extra_data}\n2: {props.extra_data2}" }
} }

View file

@ -18,6 +18,19 @@ impl Parse for ComponentBody {
impl ToTokens for ComponentBody { impl ToTokens for ComponentBody {
fn to_tokens(&self, tokens: &mut TokenStream) { fn to_tokens(&self, tokens: &mut TokenStream) {
// https://github.com/DioxusLabs/dioxus/issues/1938
// If there's only one input and the input is `props: Props`, we don't need to generate a props struct
// Just attach the non_snake_case attribute to the function
// eventually we'll dump this metadata into devtooling that lets us find all these components
if self.is_explicit_props_ident() {
let comp_fn = &self.item_fn;
tokens.append_all(quote! {
#[allow(non_snake_case)]
#comp_fn
});
return;
}
let comp_fn = self.comp_fn(); let comp_fn = self.comp_fn();
// If there's no props declared, we simply omit the props argument // If there's no props declared, we simply omit the props argument
@ -196,6 +209,18 @@ impl ComponentBody {
props_docs props_docs
} }
fn is_explicit_props_ident(&self) -> bool {
if self.item_fn.sig.inputs.len() == 1 {
if let FnArg::Typed(PatType { pat, .. }) = &self.item_fn.sig.inputs[0] {
if let Pat::Ident(ident) = pat.as_ref() {
return ident.ident == "props";
}
}
}
false
}
} }
struct DocField<'a> { struct DocField<'a> {

View file

@ -29,7 +29,7 @@ dioxus = { workspace = true }
pretty_assertions = "1.3.0" pretty_assertions = "1.3.0"
rand = "0.8.5" rand = "0.8.5"
dioxus-ssr = { workspace = true } dioxus-ssr = { workspace = true }
reqwest.workspace = true reqwest = { workspace = true}
[features] [features]
default = [] default = []