-
Notifications
You must be signed in to change notification settings - Fork 1k
[react] "Unset" missing properties #4534
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b11222f
Handle props missing from previous render
augustjk e17a7a9
Fix tests
augustjk 61e2304
Add changeset
augustjk 3dd21f0
Don't run packages/labs/react test
augustjk 0bb075c
Address feedback
augustjk a56691e
More comprehensive comment for event test
augustjk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| --- | ||
| '@lit/react': patch | ||
| --- | ||
|
|
||
| Wrapped components will now keep track of JSX props from previous render that were set as a property on the element, but are now missing, and set the property to `undefined`. Note, wrapped components still do not have "default props" and missing props will be treated the same as explicitly passing in `undefined`. | ||
|
|
||
| This fixes the previously unexpected behavior where the following JSX when first rendered with a truthy condition | ||
|
|
||
| ```jsx | ||
| return condition ? <WrappedInput disabled /> : <WrappedInput />; | ||
| ``` | ||
|
|
||
| would leave the `disabled` property and reflected attribute to be `true` even when the condition turns falsey. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -334,10 +334,7 @@ suite('createComponent', () => { | |
| assert.equal(el.getAttribute('id'), 'foo'); | ||
| assert.equal(el.id, 'foo'); | ||
|
|
||
| // We currently require passing `undefined` to "unset" rather than | ||
| // omitting the prop | ||
| // See https://github.com/lit/lit/issues/4227 | ||
| render(<Tag id={undefined} />); | ||
| render(<Tag />); | ||
| assert.equal(el.getAttribute('id'), null); | ||
| assert.equal(el.id, ''); | ||
|
|
||
|
|
@@ -383,7 +380,7 @@ suite('createComponent', () => { | |
| assert.equal(el.getAttribute('hidden'), ''); | ||
| assert.equal(el.hidden, true); | ||
|
|
||
| render(<Tag hidden={undefined} />); | ||
| render(<Tag />); | ||
| assert.equal(el.getAttribute('hidden'), null); | ||
| assert.equal(el.hidden, false); | ||
|
|
||
|
|
@@ -419,7 +416,7 @@ suite('createComponent', () => { | |
| assert.equal(el.getAttribute('draggable'), 'true'); | ||
| assert.equal(el.draggable, true); | ||
|
|
||
| render(<Tag draggable={undefined} />); | ||
| render(<Tag />); | ||
| assert.equal(el.getAttribute('draggable'), null); | ||
| assert.equal(el.draggable, false); | ||
|
|
||
|
|
@@ -457,7 +454,7 @@ suite('createComponent', () => { | |
| render(<Tag aria-checked />); | ||
| assert.equal(el.getAttribute('aria-checked'), 'true'); | ||
|
|
||
| render(<Tag aria-checked={undefined} />); | ||
| render(<Tag />); | ||
| assert.equal(el.getAttribute('aria-checked'), null); | ||
| }); | ||
| } | ||
|
|
@@ -486,21 +483,19 @@ suite('createComponent', () => { | |
| barEvent = undefined; | ||
|
|
||
| // Clear listener | ||
| // Explicitly setting `undefined` or omitting prop will clear listeners | ||
| render(<BasicElementComponent onFoo={undefined} />); | ||
| el.fire('foo'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| assert.equal(fooEvent, undefined); | ||
| el.fire('bar'); | ||
| // We do not clear event listeners unless undefined is explicitly passed in | ||
| assert.equal(barEvent!.type, 'bar'); | ||
| assert.equal(barEvent, undefined); | ||
| fooEvent = undefined; | ||
| barEvent = undefined; | ||
|
|
||
| // Reattach listener | ||
| render(<BasicElementComponent onFoo={onFoo} />); | ||
| el.fire('foo'); | ||
| assert.equal(fooEvent!.type, 'foo'); | ||
| el.fire('bar'); | ||
| assert.equal(barEvent!.type, 'bar'); | ||
|
|
||
| // Replace listener | ||
| render(<BasicElementComponent onFoo={onFoo2} />); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.