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

Merge port of yew-autoprops in Yew to yew-autoprops #10

Merged
merged 21 commits into from
Dec 4, 2023

Conversation

cecton
Copy link
Member

@cecton cecton commented Nov 5, 2023

Fixes #8
Fixes #7
Fixes #9
Fixes #3
Related to yewstack/yew#3505

@cecton
Copy link
Member Author

cecton commented Nov 5, 2023

cc @kirillsemyonkin

@kirillsemyonkin
Copy link
Collaborator

image

Seems like its generating an unexpected comma somewhere (be it struct or fn) when there are no props but there are generic types

@kirillsemyonkin
Copy link
Collaborator

Repro:

#[autoprops]
#[function_component]
pub fn Test<T>() -> Html {
    html! {}
}

@cecton
Copy link
Member Author

cecton commented Nov 5, 2023

@kirillsemyonkin fixed

@kirillsemyonkin
Copy link
Collaborator

I think to trigger CI you may wanted to rerun all jobs, sometimes I see that button in the actions section
image

@cecton
Copy link
Member Author

cecton commented Nov 5, 2023

No I really wanted to trigger the CI with a different commit hash ^_^

@cecton
Copy link
Member Author

cecton commented Nov 5, 2023

TIL that you need to add the rust version in swatinem/cache key for it to work properly 🤦‍♀️ I have like 10 repos that are not doing that huh

@kirillsemyonkin
Copy link
Collaborator

image

Here is another one

@cecton
Copy link
Member Author

cecton commented Nov 5, 2023

Fixed

@kirillsemyonkin
Copy link
Collaborator

  1. Autoprops does not require -> Html on the fn, nor HtmlResult works (seems like that is replaced by Html) - following does not work:
#[autoprops]
#[function_component]
pub fn Test() -> HtmlResult {
    Ok(html! {})
}
  1. Defaults for fn generic type params are ignored by Rust, here are three cases (doesnt work, good; works, good; doesnt work, oops):

image
image
image

@cecton
Copy link
Member Author

cecton commented Nov 5, 2023

@kirillsemyonkin fixed

Copy link
Collaborator

@kirillsemyonkin kirillsemyonkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works now for my entire project on every single component (10,280 lines of Yew code) - empty props, generics, non-cloning, auto cloning, public, private, etc etc

ranile
ranile previously requested changes Nov 5, 2023
Copy link
Member

@ranile ranile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good, just a couple of things that need addressing

src/autoprops.rs Outdated Show resolved Hide resolved
src/autoprops.rs Show resolved Hide resolved
src/autoprops.rs Outdated Show resolved Hide resolved
src/autoprops.rs Outdated Show resolved Hide resolved
@cecton cecton marked this pull request as draft November 9, 2023 10:28
cecton added a commit to yewstack/implicit-clone that referenced this pull request Nov 9, 2023
cecton added a commit to yewstack/implicit-clone that referenced this pull request Nov 9, 2023
Following the advice of @kirillsemyonkin, I'm adding a function
`implicit_clone()` which will enforce that the type is implementing
`ImplicitClone` while still actually cloning.

Related to
yewstack/yew-autoprops#10 (comment)
@cecton cecton requested a review from ranile November 9, 2023 14:18
@cecton
Copy link
Member Author

cecton commented Nov 9, 2023

@hamza1311 @kirillsemyonkin ok I think this is ready now

@cecton cecton marked this pull request as ready for review November 9, 2023 14:18
src/autoprops.rs Outdated Show resolved Hide resolved
@kirillsemyonkin
Copy link
Collaborator

What is the current status of this?

7 | fn CantAcceptReceiver(&self, b: bool) -> Html {
| ^^^^^

error: could not find #[function_component] attribute in function declaration (#[autoprops] must be placed *before* #[function_component])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we cannot enforce a function_component macro by reading the macro name as function_component can be renamed with as and can be implemented via other macros like stylist::yew::styled_component.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in e8fe2f0

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though imo we should use a separate proc macro instead of outputting the function component from an extended macro. This allows better composition:

#[styled_component]
#[autoprops]
#[function_component]
fn MyStyledComponent() -> Html {
    html! {<div class={css!("color: red;")}>{"Hello World!"}</div>}
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah #[styled] #[autoprops] #[component] / #[autoprops] #[styled] #[component] (yewstack/yew/#3447 would be a breaking change btw so stylist would need to be updated anyway) should compose well, but its up to @futursolo to make a breaking change just for that

src/autoprops.rs Outdated Show resolved Hide resolved
#[test]
fn tests_pass() {
let t = trybuild::TestCases::new();
t.pass("tests/function_component_attr/*-pass.rs");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass tests should also only be run with MSRV.
Rustc may introduce additional lints over the time to fail pass tests.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests breaking somehow to me sounds like a good idea, despite being slightly annoying upon trying to perform an unrelated PR (already happened with clippy before). Maybe have them run under both MSRV and latest stable so we can see whether such a lint change occured?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kirillsemyonkin it's already what I did here

But in Yew we only run them against MSRV.

imo it's best to run it on both because we need the thing to keep working on stable and to be alerted asap when it's not.

I don't mind restricting this test to MSRV though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@futursolo do you agree with the argument or you still prefer the passing test to run only on MSRV?

@cecton
Copy link
Member Author

cecton commented Nov 17, 2023

@yewstack/yew can I have a final review on this?

@Madoshakalaka
Copy link

@cecton hi you are my angel, thanks for the work

@kirillsemyonkin
Copy link
Collaborator

@yewstack/yew can I have a final review on this?

Can we skip such a review since it is more-or-less separate from Yew and proceed to merge? We can have extra merges later, independent of Yew's slow cycle

@kirillsemyonkin
Copy link
Collaborator

Ideally anyone's work on a stylist PR for #[styled_component] -> #[styled] (for #[styled] #[autoprops] #[component] progress) should happen somewhere around now as well

@cecton
Copy link
Member Author

cecton commented Dec 4, 2023

Can we skip such a review since it is more-or-less separate from Yew and proceed to merge? We can have extra merges later, independent of Yew's slow cycle

Yeah I think the other maintainers are a bit overbooked at the moment so let's merge it as is. Worst case scenario we open issues or fix things later on.

@cecton cecton merged commit 8c3bc87 into yewstack:main Dec 4, 2023
2 checks passed
@cecton cecton deleted the merge-yew-port-autoprops-to-here branch December 4, 2023 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants