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

Add default props in cloneElement. #3968

Merged
merged 4 commits into from
Apr 15, 2023

Conversation

nnhk23
Copy link

@nnhk23 nnhk23 commented Apr 12, 2023

Summary
This PR added defaultProps & a few adjustments how Preact handles undefined properties in cloneElement. Currently, any properties in props would be used to override normalizedProps in Preact without any checks. However this is being handled differently in React where there will be a check in place to skip the override when config[propName] (props[i] in our case) is undefined.

Issue
Check these 2 code sandbox, the component's color should not be override by an undefined property:

@github-actions
Copy link

github-actions bot commented Apr 12, 2023

📊 Tachometer Benchmark Results

Summary

duration

  • 02_replace1k: unsure 🔍 -4% - +1% (-4.70ms - +1.31ms)
    preact-local vs preact-master
  • 03_update10th1k_x16: unsure 🔍 -3% - +5% (-1.49ms - +2.33ms)
    preact-local vs preact-master
  • 07_create10k: unsure 🔍 -1% - +1% (-18.79ms - +18.49ms)
    preact-local vs preact-master
  • filter_list: unsure 🔍 -1% - +2% (-0.13ms - +0.39ms)
    preact-local vs preact-master
  • hydrate1k: unsure 🔍 -3% - +3% (-5.59ms - +5.84ms)
    preact-local vs preact-master
  • many_updates: unsure 🔍 -2% - +4% (-0.62ms - +1.50ms)
    preact-local vs preact-master
  • text_update: unsure 🔍 -2% - +4% (-0.08ms - +0.16ms)
    preact-local vs preact-master
  • todo: unsure 🔍 -3% - +2% (-1.92ms - +1.36ms)
    preact-local vs preact-master

usedJSHeapSize

  • 02_replace1k: unsure 🔍 -1% - +0% (-0.02ms - +0.01ms)
    preact-local vs preact-master
  • 03_update10th1k_x16: unsure 🔍 -0% - +0% (-0.01ms - +0.01ms)
    preact-local vs preact-master
  • 07_create10k: unsure 🔍 -0% - +0% (-0.04ms - +0.03ms)
    preact-local vs preact-master
  • filter_list: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-master
  • hydrate1k: unsure 🔍 -1% - +0% (-0.06ms - +0.03ms)
    preact-local vs preact-master
  • many_updates: unsure 🔍 -0% - +1% (-0.02ms - +0.03ms)
    preact-local vs preact-master
  • text_update: slower ❌ 1% - 4% (0.01ms - 0.03ms)
    preact-local vs preact-master
  • todo: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-master

Results

02_replace1k

duration

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master113.87ms - 117.60ms-unsure 🔍
-1% - +4%
-1.31ms - +4.70ms
unsure 🔍
-2% - +3%
-2.60ms - +3.38ms
preact-local111.69ms - 116.40msunsure 🔍
-4% - +1%
-4.70ms - +1.31ms
-unsure 🔍
-4% - +2%
-4.62ms - +2.02ms
preact-hooks113.01ms - 117.68msunsure 🔍
-3% - +2%
-3.38ms - +2.60ms
unsure 🔍
-2% - +4%
-2.02ms - +4.62ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master3.37ms - 3.39ms-unsure 🔍
-0% - +1%
-0.01ms - +0.02ms
faster ✔
0% - 1%
0.00ms - 0.04ms
preact-local3.37ms - 3.39msunsure 🔍
-1% - +0%
-0.02ms - +0.01ms
-faster ✔
0% - 1%
0.01ms - 0.04ms
preact-hooks3.39ms - 3.41msslower ❌
0% - 1%
0.00ms - 0.04ms
slower ❌
0% - 1%
0.01ms - 0.04ms
-

run-warmup-0

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master42.22ms - 44.32ms-unsure 🔍
-3% - +3%
-1.31ms - +1.15ms
unsure 🔍
-5% - +0%
-2.40ms - +0.17ms
preact-local42.70ms - 43.99msunsure 🔍
-3% - +3%
-1.15ms - +1.31ms
-faster ✔
0% - 5%
0.06ms - 2.01ms
preact-hooks43.65ms - 45.12msunsure 🔍
-0% - +6%
-0.17ms - +2.40ms
slower ❌
0% - 5%
0.06ms - 2.01ms
-

run-warmup-1

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master58.79ms - 61.85ms-unsure 🔍
-3% - +4%
-1.62ms - +2.19ms
unsure 🔍
-4% - +2%
-2.71ms - +1.23ms
preact-local58.90ms - 61.17msunsure 🔍
-4% - +3%
-2.19ms - +1.62ms
-unsure 🔍
-4% - +1%
-2.70ms - +0.65ms
preact-hooks59.82ms - 62.30msunsure 🔍
-2% - +5%
-1.23ms - +2.71ms
unsure 🔍
-1% - +5%
-0.65ms - +2.70ms
-

run-warmup-2

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master37.90ms - 42.83ms-unsure 🔍
-8% - +7%
-3.09ms - +2.81ms
unsure 🔍
-7% - +8%
-2.67ms - +3.27ms
preact-local38.89ms - 42.13msunsure 🔍
-7% - +8%
-2.81ms - +3.09ms
-unsure 🔍
-5% - +7%
-1.88ms - +2.77ms
preact-hooks38.40ms - 41.72msunsure 🔍
-8% - +7%
-3.27ms - +2.67ms
unsure 🔍
-7% - +5%
-2.77ms - +1.88ms
-

run-warmup-3

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master50.70ms - 53.97ms-unsure 🔍
-3% - +7%
-1.63ms - +3.51ms
faster ✔
1% - 9%
0.54ms - 4.76ms
preact-local49.41ms - 53.38msunsure 🔍
-7% - +3%
-3.51ms - +1.63ms
-faster ✔
2% - 11%
1.19ms - 5.98ms
preact-hooks53.65ms - 56.32msslower ❌
1% - 9%
0.54ms - 4.76ms
slower ❌
2% - 12%
1.19ms - 5.98ms
-

run-warmup-4

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master49.71ms - 52.39ms-unsure 🔍
-6% - +3%
-3.24ms - +1.38ms
unsure 🔍
-5% - +2%
-2.54ms - +1.26ms
preact-local50.10ms - 53.86msunsure 🔍
-3% - +6%
-1.38ms - +3.24ms
-unsure 🔍
-4% - +5%
-2.02ms - +2.61ms
preact-hooks50.34ms - 53.03msunsure 🔍
-2% - +5%
-1.26ms - +2.54ms
unsure 🔍
-5% - +4%
-2.61ms - +2.02ms
-

run-final

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master29.79ms - 31.71ms-unsure 🔍
-8% - +3%
-2.46ms - +0.95ms
unsure 🔍
-10% - +1%
-3.18ms - +0.29ms
preact-local30.10ms - 32.92msunsure 🔍
-3% - +8%
-0.95ms - +2.46ms
-unsure 🔍
-8% - +4%
-2.71ms - +1.33ms
preact-hooks30.75ms - 33.64msunsure 🔍
-1% - +10%
-0.29ms - +3.18ms
unsure 🔍
-4% - +9%
-1.33ms - +2.71ms
-
03_update10th1k_x16

duration

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master49.13ms - 51.53ms-unsure 🔍
-5% - +3%
-2.33ms - +1.49ms
unsure 🔍
-3% - +4%
-1.49ms - +2.02ms
preact-local49.27ms - 52.23msunsure 🔍
-3% - +5%
-1.49ms - +2.33ms
-unsure 🔍
-3% - +5%
-1.27ms - +2.65ms
preact-hooks48.78ms - 51.34msunsure 🔍
-4% - +3%
-2.02ms - +1.49ms
unsure 🔍
-5% - +2%
-2.65ms - +1.27ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master3.29ms - 3.31ms-unsure 🔍
-0% - +0%
-0.01ms - +0.01ms
faster ✔
0% - 1%
0.01ms - 0.03ms
preact-local3.30ms - 3.30msunsure 🔍
-0% - +0%
-0.01ms - +0.01ms
-faster ✔
0% - 1%
0.01ms - 0.03ms
preact-hooks3.31ms - 3.33msslower ❌
0% - 1%
0.01ms - 0.03ms
slower ❌
0% - 1%
0.01ms - 0.03ms
-
07_create10k

duration

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master1910.07ms - 1938.74ms-unsure 🔍
-1% - +1%
-18.49ms - +18.79ms
unsure 🔍
-1% - +0%
-26.45ms - +9.45ms
preact-local1912.34ms - 1936.17msunsure 🔍
-1% - +1%
-18.79ms - +18.49ms
-unsure 🔍
-1% - +0%
-24.74ms - +7.43ms
preact-hooks1922.10ms - 1943.71msunsure 🔍
-0% - +1%
-9.45ms - +26.45ms
unsure 🔍
-0% - +1%
-7.43ms - +24.74ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master25.39ms - 25.43ms-unsure 🔍
-0% - +0%
-0.03ms - +0.04ms
unsure 🔍
+0% - +0%
+0.01ms - +0.05ms
preact-local25.38ms - 25.43msunsure 🔍
-0% - +0%
-0.04ms - +0.03ms
-unsure 🔍
+0% - +0%
+0.00ms - +0.05ms
preact-hooks25.38ms - 25.38msunsure 🔍
-0% - -0%
-0.05ms - -0.01ms
unsure 🔍
-0% - -0%
-0.05ms - -0.00ms
-
filter_list

duration

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master22.31ms - 22.64ms-unsure 🔍
-2% - +1%
-0.39ms - +0.13ms
unsure 🔍
-2% - +0%
-0.39ms - +0.11ms
preact-local22.40ms - 22.81msunsure 🔍
-1% - +2%
-0.13ms - +0.39ms
-unsure 🔍
-1% - +1%
-0.29ms - +0.26ms
preact-hooks22.43ms - 22.81msunsure 🔍
-0% - +2%
-0.11ms - +0.39ms
unsure 🔍
-1% - +1%
-0.26ms - +0.29ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master1.43ms - 1.44ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
faster ✔
2% - 2%
0.02ms - 0.03ms
preact-local1.43ms - 1.44msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-faster ✔
1% - 2%
0.02ms - 0.03ms
preact-hooks1.46ms - 1.47msslower ❌
2% - 2%
0.02ms - 0.03ms
slower ❌
1% - 2%
0.02ms - 0.03ms
-
hydrate1k

duration

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master197.86ms - 206.83ms-unsure 🔍
-3% - +3%
-5.84ms - +5.59ms
unsure 🔍
-4% - +2%
-7.26ms - +4.24ms
preact-local198.93ms - 206.01msunsure 🔍
-3% - +3%
-5.59ms - +5.84ms
-unsure 🔍
-3% - +2%
-6.43ms - +3.66ms
preact-hooks200.26ms - 207.45msunsure 🔍
-2% - +4%
-4.24ms - +7.26ms
unsure 🔍
-2% - +3%
-3.66ms - +6.43ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master6.02ms - 6.08ms-unsure 🔍
-0% - +1%
-0.03ms - +0.06ms
unsure 🔍
-1% - +1%
-0.05ms - +0.03ms
preact-local6.00ms - 6.07msunsure 🔍
-1% - +0%
-0.06ms - +0.03ms
-unsure 🔍
-1% - +0%
-0.07ms - +0.02ms
preact-hooks6.03ms - 6.09msunsure 🔍
-1% - +1%
-0.03ms - +0.05ms
unsure 🔍
-0% - +1%
-0.02ms - +0.07ms
-
many_updates

duration

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master33.03ms - 34.57ms-unsure 🔍
-4% - +2%
-1.50ms - +0.62ms
unsure 🔍
-4% - +2%
-1.53ms - +0.69ms
preact-local33.51ms - 34.96msunsure 🔍
-2% - +4%
-0.62ms - +1.50ms
-unsure 🔍
-3% - +3%
-1.06ms - +1.10ms
preact-hooks33.42ms - 35.02msunsure 🔍
-2% - +5%
-0.69ms - +1.53ms
unsure 🔍
-3% - +3%
-1.10ms - +1.06ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master4.49ms - 4.53ms-unsure 🔍
-1% - +0%
-0.03ms - +0.02ms
unsure 🔍
-1% - +0%
-0.05ms - +0.01ms
preact-local4.50ms - 4.54msunsure 🔍
-0% - +1%
-0.02ms - +0.03ms
-unsure 🔍
-1% - +0%
-0.04ms - +0.02ms
preact-hooks4.51ms - 4.55msunsure 🔍
-0% - +1%
-0.01ms - +0.05ms
unsure 🔍
-0% - +1%
-0.02ms - +0.04ms
-
text_update

duration

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master3.42ms - 3.54ms-unsure 🔍
-4% - +2%
-0.16ms - +0.08ms
faster ✔
3% - 8%
0.12ms - 0.29ms
preact-local3.42ms - 3.62msunsure 🔍
-2% - +4%
-0.08ms - +0.16ms
-faster ✔
1% - 8%
0.05ms - 0.28ms
preact-hooks3.62ms - 3.75msslower ❌
3% - 8%
0.12ms - 0.29ms
slower ❌
1% - 8%
0.05ms - 0.28ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master0.70ms - 0.71ms-faster ✔
1% - 4%
0.01ms - 0.03ms
slower ❌
2% - 4%
0.01ms - 0.03ms
preact-local0.71ms - 0.73msslower ❌
1% - 4%
0.01ms - 0.03ms
-slower ❌
4% - 7%
0.03ms - 0.04ms
preact-hooks0.68ms - 0.69msfaster ✔
2% - 4%
0.01ms - 0.03ms
faster ✔
4% - 6%
0.03ms - 0.04ms
-
todo

duration

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master73.05ms - 75.44ms-unsure 🔍
-2% - +3%
-1.36ms - +1.92ms
faster ✔
1% - 5%
0.37ms - 3.58ms
preact-local72.84ms - 75.08msunsure 🔍
-3% - +2%
-1.92ms - +1.36ms
-faster ✔
1% - 5%
0.71ms - 3.80ms
preact-hooks75.15ms - 77.29msslower ❌
0% - 5%
0.37ms - 3.58ms
slower ❌
1% - 5%
0.71ms - 3.80ms
-

usedJSHeapSize

VersionAvg timevs preact-mastervs preact-localvs preact-hooks
preact-master0.92ms - 0.93ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
faster ✔
2% - 4%
0.02ms - 0.04ms
preact-local0.92ms - 0.92msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-faster ✔
3% - 4%
0.02ms - 0.04ms
preact-hooks0.95ms - 0.96msslower ❌
2% - 4%
0.02ms - 0.04ms
slower ❌
3% - 4%
0.02ms - 0.04ms
-

tachometer-reporter-action v2 for Benchmarks

Copy link
Member

@marvinhagemeister marvinhagemeister left a comment

Choose a reason for hiding this comment

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

This is a great catch! I wasn't aware that defaultProps play a role for cloneElement. Love the codesandbox comparisons and that you already included a test case in your proposed changes. This is a fantastic PR!

Copy link
Member

@andrewiggins andrewiggins left a comment

Choose a reason for hiding this comment

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

Thanks Kim!!

@andrewiggins andrewiggins merged commit 362bcd8 into preactjs:master Apr 15, 2023
jpnelson added a commit to jpnelson/preact that referenced this pull request Apr 21, 2023
@JoviDeCroock JoviDeCroock mentioned this pull request May 13, 2023
JoviDeCroock added a commit that referenced this pull request Jan 22, 2024
JoviDeCroock added a commit that referenced this pull request Jan 23, 2024
* backport #3968

* backport #3964

* backport #3997

* backport #3995

* backport #3970

* backport #3971

* backport #3990

* backport #3963

* backport #3962

* backport #3960

* backport #3956

* Revert "backport #3963"

This reverts commit 86a372a.

* define public type

* fix newline issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants