leptos-rs/leptos · error

Unrecognized #[server] attribute, expected #[server(default)

Error message

Unrecognized #[server] attribute, expected #[server(default)] or #[server(rename = "fieldName")]

What it means

On struct fields of a server-function argument struct, the macro only recognizes #[server(default)] and #[server(rename = "fieldName")] (and paths for the latter form). Any other #[server(...)] meta on a field is rejected with this message naming the two allowed forms.

Source

Thrown at server_fn_macro/src/lib.rs:1405

                            Ok(attr.clone())
                        }
                        // #[server(default = "value")]
                        Meta::NameValue(name_value)
                            if name_value.path.is_ident("default") =>
                        {
                            Ok(attr.clone())
                        }
                        // #[server(skip)]
                        Meta::Path(path) if path.is_ident("skip") => {
                            Ok(attr.clone())
                        }
                        // #[server(rename = "value")]
                        Meta::NameValue(name_value)
                            if name_value.path.is_ident("rename") =>
                        {
                            Ok(attr.clone())
                        }
                        _ => Err(Error::new(
                            attr.span(),
                            "Unrecognized #[server] attribute, expected \
                             #[server(default)] or #[server(rename = \
                             \"fieldName\")]",
                        )),
                    }
                } else if attr.path().is_ident("doc") {
                    // Allow #[doc = "documentation"]
                    Ok(attr.clone())
                } else if attr.path().is_ident("allow") {
                    // Allow #[allow(...)]
                    Ok(attr.clone())
                } else if attr.path().is_ident("deny") {
                    // Allow #[deny(...)]
                    Ok(attr.clone())
                } else if attr.path().is_ident("ignore") {
                    // Allow #[ignore]
                    Ok(attr.clone())

View on GitHub (pinned to 32d20f6c9d)

Solutions

  1. Restrict field attributes to #[server(default)] or #[server(rename = "fieldName").
  2. For other serde behavior, use the actual serde attributes handled by your input derive instead of #[server(...)].
  3. Fix typos in `rename` and supply the required "value".

Example fix

// before
#[server(skip)]
field: String,
// after
#[serde(skip)]
#[server]
field: String,
Defensive patterns

Strategy: validation

Validate before calling

let allowed = ["default", "rename"];
let attr_meta = "skip"; // contents of #[server(...)] on a field
assert!(allowed.contains(&attr_meta) || attr_meta.starts_with("rename "), "field attr must be #[server(default)] or #[server(rename = \"x\")]" );

Prevention

When it happens

Trigger: #[server(skip)] or #[server(flatten)] on a field; #[server(rename)] without a value; copying serde-style attributes onto fields where only default/rename are supported.

Common situations: Developers assuming full serde attribute parity; migrating from another derive that supported more field options; typo like `renamed = "x"`.

Related errors


AI-assisted analysis of leptos-rs/leptos@32d20f6c9d (2026-09-01). Data as JSON: /api/errors/524be76320266830. Report an issue: GitHub.