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

[react] "Unset" missing properties #4534

Merged
merged 6 commits into from
Feb 2, 2024
Merged

[react] "Unset" missing properties #4534

merged 6 commits into from
Feb 2, 2024

Conversation

augustjk
Copy link
Member

@augustjk augustjk commented Feb 1, 2024

Fixes #4497
Also related #4227

What changed

We now collect previous element props in a map and actually check off ones that we update. We then go through any remaining and set them all as undefined.

Open questions

1. Is patch bump right for this?

It could be considered a bugfix, or it could even be considered breaking. Or a new "feature" of handling unset properties?

2. Is undefined the correct behavior?

undefined feels most correct in terms of semantics of "unsetting", but I wanted to see what React's future custom element support would do and it seems react-dom@experimental will actually set the property as null if it's missing.
Playground: https://lit.dev/playground/#gist=001005b1cfb39fd03ccb37e841d256e5
(The current value of the property is logged in the console)

Resolution

We'll include this in a patch release as the existing behavior is considered unexpected, therefore this is a bugfix.

Filed an issue with React regarding they're behavior of setting null. Setting to undefined seems like the semantically correct thing to do.

Copy link

changeset-bot bot commented Feb 1, 2024

🦋 Changeset detected

Latest commit: a56691e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@lit/react Patch
@lit-internal/test-elements-react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Feb 1, 2024

📊 Tachometer Benchmark Results

Summary

nop-update

  • this-change, tip-of-tree, previous-release: unsure 🔍 -5% - +3% (-0.58ms - +0.38ms)
    this-change vs tip-of-tree

render

  • this-change: 47.78ms - 50.41ms
  • this-change, tip-of-tree, previous-release: slower ❌ 0% - 6% (0.01ms - 1.12ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -2% - +4% (-0.52ms - +1.26ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -2% - +2% (-0.58ms - +0.64ms)
    this-change vs tip-of-tree

update

  • this-change: 551.15ms - 565.83ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -8% - +4% (-3.28ms - +1.47ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -2% - +2% (-1.67ms - +1.45ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -2% - +2% (-10.84ms - +8.20ms)
    this-change vs tip-of-tree

update-reflect

  • this-change: 549.46ms - 556.78ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -2% - +1% (-12.35ms - +5.71ms)
    this-change vs tip-of-tree

Results

this-change

render

VersionAvg timevs
47.78ms - 50.41ms-

update

VersionAvg timevs
551.15ms - 565.83ms-

update-reflect

VersionAvg timevs
549.46ms - 556.78ms-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
18.65ms - 19.48ms-slower ❌
0% - 6%
0.01ms - 1.12ms
unsure 🔍
-2% - +4%
-0.40ms - +0.81ms
tip-of-tree
tip-of-tree
18.13ms - 18.87msfaster ✔
0% - 6%
0.01ms - 1.12ms
-unsure 🔍
-5% - +1%
-0.93ms - +0.21ms
previous-release
previous-release
18.43ms - 19.29msunsure 🔍
-4% - +2%
-0.81ms - +0.40ms
unsure 🔍
-1% - +5%
-0.21ms - +0.93ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
38.13ms - 41.38ms-unsure 🔍
-8% - +4%
-3.28ms - +1.47ms
unsure 🔍
-6% - +6%
-2.31ms - +2.49ms
tip-of-tree
tip-of-tree
38.93ms - 42.39msunsure 🔍
-4% - +8%
-1.47ms - +3.28ms
-unsure 🔍
-4% - +9%
-1.48ms - +3.47ms
previous-release
previous-release
37.90ms - 41.43msunsure 🔍
-6% - +6%
-2.49ms - +2.31ms
unsure 🔍
-8% - +4%
-3.47ms - +1.48ms
-

nop-update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
10.65ms - 11.29ms-unsure 🔍
-5% - +3%
-0.58ms - +0.38ms
unsure 🔍
-5% - +5%
-0.56ms - +0.51ms
tip-of-tree
tip-of-tree
10.72ms - 11.43msunsure 🔍
-3% - +5%
-0.38ms - +0.58ms
-unsure 🔍
-4% - +6%
-0.47ms - +0.63ms
previous-release
previous-release
10.57ms - 11.42msunsure 🔍
-5% - +5%
-0.51ms - +0.56ms
unsure 🔍
-6% - +4%
-0.63ms - +0.47ms
-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
33.16ms - 34.75ms-unsure 🔍
-2% - +4%
-0.52ms - +1.26ms
unsure 🔍
-2% - +3%
-0.68ms - +1.15ms
tip-of-tree
tip-of-tree
33.19ms - 34.00msunsure 🔍
-4% - +2%
-1.26ms - +0.52ms
-unsure 🔍
-2% - +1%
-0.74ms - +0.47ms
previous-release
previous-release
33.27ms - 34.17msunsure 🔍
-3% - +2%
-1.15ms - +0.68ms
unsure 🔍
-1% - +2%
-0.47ms - +0.74ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
68.50ms - 70.52ms-unsure 🔍
-2% - +2%
-1.67ms - +1.45ms
unsure 🔍
-2% - +2%
-1.50ms - +1.31ms
tip-of-tree
tip-of-tree
68.42ms - 70.81msunsure 🔍
-2% - +2%
-1.45ms - +1.67ms
-unsure 🔍
-2% - +2%
-1.53ms - +1.55ms
previous-release
previous-release
68.63ms - 70.58msunsure 🔍
-2% - +2%
-1.31ms - +1.50ms
unsure 🔍
-2% - +2%
-1.55ms - +1.53ms
-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
31.78ms - 32.64ms-unsure 🔍
-2% - +2%
-0.58ms - +0.64ms
unsure 🔍
-1% - +3%
-0.41ms - +0.85ms
tip-of-tree
tip-of-tree
31.75ms - 32.61msunsure 🔍
-2% - +2%
-0.64ms - +0.58ms
-unsure 🔍
-1% - +3%
-0.44ms - +0.82ms
previous-release
previous-release
31.53ms - 32.45msunsure 🔍
-3% - +1%
-0.85ms - +0.41ms
unsure 🔍
-3% - +1%
-0.82ms - +0.44ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
528.59ms - 541.72ms-unsure 🔍
-2% - +2%
-10.84ms - +8.20ms
unsure 🔍
-2% - +2%
-10.45ms - +8.13ms
tip-of-tree
tip-of-tree
529.58ms - 543.37msunsure 🔍
-2% - +2%
-8.20ms - +10.84ms
-unsure 🔍
-2% - +2%
-9.37ms - +9.68ms
previous-release
previous-release
529.74ms - 542.89msunsure 🔍
-2% - +2%
-8.13ms - +10.45ms
unsure 🔍
-2% - +2%
-9.68ms - +9.37ms
-

update-reflect

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
530.69ms - 542.67ms-unsure 🔍
-2% - +1%
-12.35ms - +5.71ms
unsure 🔍
-2% - +1%
-9.47ms - +7.83ms
tip-of-tree
tip-of-tree
533.23ms - 546.76msunsure 🔍
-1% - +2%
-5.71ms - +12.35ms
-unsure 🔍
-1% - +2%
-6.70ms - +11.70ms
previous-release
previous-release
531.25ms - 543.74msunsure 🔍
-1% - +2%
-7.83ms - +9.47ms
unsure 🔍
-2% - +1%
-11.70ms - +6.70ms
-

tachometer-reporter-action v2 for Benchmarks

Copy link
Contributor

github-actions bot commented Feb 1, 2024

The size of lit-html.js and lit-core.min.js are as expected.

@@ -171,7 +171,6 @@
"./packages/labs/gen-wrapper-vue:test",
"./packages/labs/nextjs:test",
"./packages/labs/preact-signals:test",
"./packages/labs/react:test",
Copy link
Member Author

@augustjk augustjk Feb 1, 2024

Choose a reason for hiding this comment

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

This feels like a band-aid. I had to remove it because there's a copy of tests in packages/labs/react that are now stale and fail. I don't think it makes sense to update those files, and I don't think there's reason to keep things like tests and rollup builds in the labs directories for graduated packages.

Copy link
Contributor

@AndrewJakubowicz AndrewJakubowicz Feb 1, 2024

Choose a reason for hiding this comment

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

Strongly agree. Are there files to delete?

Copy link
Member Author

Choose a reason for hiding this comment

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

There are. I think they can be done as a separate chore task. Nothing super pressing.

@@ -490,17 +487,15 @@ suite('createComponent', () => {
el.fire('foo');
Copy link
Contributor

Choose a reason for hiding this comment

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

The line above this can be update to either no have the explicit undefined, or the comment above it can mention that both explicit undefined or omitting property will clear listener.

Copy link
Contributor

@AndrewJakubowicz AndrewJakubowicz left a comment

Choose a reason for hiding this comment

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

Awesome!

Would be cool to link to the React issue (where they are currently setting to null).
Discussed options IRL.

@augustjk
Copy link
Member Author

augustjk commented Feb 1, 2024

Regarding React's current behavior of setting null, filed facebook/react#28203

- add link to react issue
- remove unnecessary type arg
@augustjk augustjk merged commit d68f5c7 into main Feb 2, 2024
9 checks passed
@augustjk augustjk deleted the react-unset-prop branch February 2, 2024 01:02
@lit-robot lit-robot mentioned this pull request Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants