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

[Docs]: Update Docs for Proper #[layout] and #[end_layout] Macros Usage in Enums #3211

Open
wiseaidev opened this issue Nov 13, 2024 · 2 comments
Labels
needs reproduction An issue that is missing a reproduction router Related to the router implementation

Comments

@wiseaidev
Copy link

Hiya ( ´ ω ` )ノ゙,

This is not a critical issue, but I’ve noticed a bug with layout and routes ordering when defining multiple layouts for different pages.

Here’s an example that works:

#[derive(Clone, Routable, Debug, PartialEq, Serialize, Deserialize)]  
pub enum Route {  
    #[layout(HomeNavBar)]  
    #[route("/")]  
    Home {},  
    #[end_layout]  

    #[layout(LoginNavBar)]  
    #[route("/login")]  
    Login {},  
    #[end_layout]  

    #[route("/dashboard")]  
    Dashboard {},  
}  

However, if you reorder the routes like this:

#[derive(Clone, Routable, Debug, PartialEq, Serialize, Deserialize)]  
pub enum Route {  
    #[layout(HomeNavBar)]  
    #[route("/")]  
    Home {},  
    #[end_layout]

    #[route("/dashboard")] // Notice this route between the layouts  
    Dashboard {},  

    #[layout(LoginNavBar)]  
    #[route("/login")]  
    Login {},  
    #[end_layout]  
}  

The routing doesn’t work as expected.

Just wanted to raise this to your attention.

Best

@ealmloff
Copy link
Member

I was not able to reproduce this issue with the git version of dioxus with either version of the router. Here is my attempt: https://github.com/ealmloff/fail-repo-3211

@ealmloff ealmloff added router Related to the router implementation needs reproduction An issue that is missing a reproduction labels Nov 13, 2024
@wiseaidev
Copy link
Author

I was not able to reproduce this issue with the git version of dioxus with either version of the router. Here is my attempt: https://github.com/ealmloff/fail-repo-3211

Thanks for the reply! But, your enum router example doesn't include a #[end_layout] macro at the end to close the corresponding #[layout] macro. In this case, it will raise:

error: expected identifier, found `}`
  --> src/main.rs:19:1
   |
4  | pub enum Route {  
   |          ----- while parsing this enum
...
19 | }  
   | ^ expected identifier
   |
   = help: enum variants can be `Variant`, `Variant = <integer>`, `Variant(Type, ..., TypeN)` or `Variant { fields: Types }`

  ❌ Build failed.
| 💼 Waiting to start building the project...                                   Error: 🚫 Serving project failed:

However, I realized that in Rust, macros are designed to modify the item or block immediately following them. Since #[end_layout] isn't attached to any item, it causes a bug. I think it is better to update the documentation to inform users that layouts must be properly scoped and ensure each #[layout] is correctly closed or inferred by the macro.

@wiseaidev wiseaidev changed the title [Router Bug]: Layout and Routes Ordering Bug [Docs]: Update Docs for Proper #[layout] and #[end_layout] Macros Usage in Enums Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs reproduction An issue that is missing a reproduction router Related to the router implementation
Projects
None yet
Development

No branches or pull requests

2 participants