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

Remove special handing of struct fields of type Option in derive(Properties) #3398

Merged
merged 6 commits into from
Sep 23, 2023

Conversation

its-the-shrimp
Copy link
Contributor

@its-the-shrimp its-the-shrimp commented Sep 9, 2023

Description

Fixes #3395

Checklist

  • I have reviewed my own code
  • I have added tests (not sure if a new test is needed after removing a feature)

@github-actions
Copy link

github-actions bot commented Sep 9, 2023

Visit the preview URL for this PR (updated for commit 4de7160):

https://yew-rs-api--pr3398-remove-option-specia-b2jmg0pe.web.app

(expires Tue, 19 Sep 2023 20:07:51 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

@github-actions
Copy link

github-actions bot commented Sep 9, 2023

Size Comparison

examples master (KB) pull request (KB) diff (KB) diff (%)
async_clock 102.637 102.637 0 0.000%
boids 175.874 175.874 0 0.000%
communication_child_to_parent 95.527 95.527 0 0.000%
communication_grandchild_with_grandparent 109.263 109.263 0 0.000%
communication_grandparent_to_grandchild 105.948 105.948 0 0.000%
communication_parent_to_child 93.015 93.015 0 0.000%
contexts 111.238 111.238 0 0.000%
counter 89.423 89.423 0 0.000%
counter_functional 90.157 90.157 0 0.000%
dyn_create_destroy_apps 92.596 92.596 0 0.000%
file_upload 103.755 103.755 0 0.000%
function_memory_game 174.855 174.855 0 0.000%
function_router 352.738 352.738 0 0.000%
function_todomvc 163.751 163.751 0 0.000%
futures 227.985 227.985 0 0.000%
game_of_life 112.589 112.589 0 0.000%
immutable 189.449 189.449 0 0.000%
inner_html 86.205 86.205 0 0.000%
js_callback 113.448 113.537 +0.089 +0.078%
keyed_list 201.528 201.528 0 0.000%
mount_point 89.414 89.414 0 0.000%
nested_list 114.828 114.828 0 0.000%
node_refs 96.516 96.516 0 0.000%
password_strength 1584.312 1584.312 0 0.000%
portals 98.591 98.591 0 0.000%
router 318.857 318.857 0 0.000%
simple_ssr 144.353 144.441 +0.089 +0.062%
ssr_router 390.498 390.498 0 0.000%
suspense 119.124 119.242 +0.118 +0.099%
timer 92.023 92.023 0 0.000%
timer_functional 100.690 100.690 0 0.000%
todomvc 143.905 143.905 0 0.000%
two_apps 90.122 90.122 0 0.000%
web_worker_fib 154.714 154.714 0 0.000%
webgl 88.780 88.780 0 0.000%

✅ None of the examples has changed their size significantly.

@github-actions
Copy link

github-actions bot commented Sep 9, 2023

Benchmark - SSR

Yew Master

Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 428.321 429.623 429.016 0.424
Hello World 10 780.283 784.982 781.197 1.428
Function Router 10 2504.406 2522.572 2512.630 5.413
Concurrent Task 10 1007.339 1011.398 1008.742 1.167
Many Providers 10 1738.228 1783.301 1750.761 13.336

Pull Request

Benchmark Round Min (ms) Max (ms) Mean (ms) Standard Deviation
Baseline 10 424.838 426.496 425.567 0.464
Hello World 10 747.628 750.016 748.633 0.861
Function Router 10 2457.074 2476.903 2464.585 5.372
Concurrent Task 10 1008.237 1009.178 1008.634 0.287
Many Providers 10 1742.475 1791.777 1765.503 17.589

@kirillsemyonkin
Copy link
Contributor

Does converting T into Some::<T> still work? impl<T> IntoPropValue<Option<T>> for T says it probably should.

@its-the-shrimp
Copy link
Contributor Author

added a test for that, it passes

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.

Thanks for the PR! It looks good, just a couple of comments, only related to tests

Comment on lines 223 to 234
mod t12 {
#[derive(::std::clone::Clone, ::yew::Properties, ::std::cmp::PartialEq)]
pub struct Props<T: ::std::clone::Clone + ::std::cmp::PartialEq> {
value: ::std::option::Option<T>,
}

fn optional_prop_generics_should_work() {
::yew::props! { Props::<::std::primitive::bool> { } };
::yew::props! { Props::<::std::primitive::bool> { value: true } };
}
}

Copy link
Member

Choose a reason for hiding this comment

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

Why remove this test? We should not be removing tests. I would like to have this change not come at the cost of functionality. Please add the test back

Copy link
Contributor

Choose a reason for hiding this comment

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

This test (or half of it) would go into fail.rs then, as it produces the problem this PR addresses.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also I should note that tests being removed all the time is a normal procedure for many developers. Tests can be removed if they do not reflect current reality (i.e. do not pass, in this case because behavior is opposite to what previously was tested for), are covered by other tests (which have been added (will be added per your suggestions) in this PR by the way), or simply poorly written or considered more of a burden for development than the sought for assistance they are supposed to give.

Copy link
Member

Choose a reason for hiding this comment

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

Also I should note that tests being removed all the time is a normal procedure for many developers. Tests can be removed if they do not reflect current reality (i.e. do not pass, in this case because behavior is opposite to what previously was tested for), are covered by other tests (which have been added (will be added per your suggestions) in this PR by the way), or simply poorly written or considered more of a burden for development than the sought for assistance they are supposed to give.

Absolutely, but in this case, the test can be updated to be passed and covers a very important functionality: generic props. We should have a passing test for that feature


#[::yew::function_component]
fn Main() -> ::yew::html::Html {
::yew::html! { <Inner field1=3 field2=5/> }
Copy link
Member

Choose a reason for hiding this comment

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

Can you also add a case where only the required field is passed? Also, please add an identical test but failing where it doesn't pass the required prop.

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.

Thanks! Looks good to me

@ranile ranile added breaking change A-yew-macro Area: The yew-macro crate labels Sep 22, 2023
@futursolo futursolo merged commit ce7702e into yewstack:master Sep 23, 2023
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-yew-macro Area: The yew-macro crate breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Property fields of type Option<T> are not mandatory
4 participants