-
Notifications
You must be signed in to change notification settings - Fork 47.8k
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 the use of proxies for synthetic events in DEV #13225
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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 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 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 |
---|---|---|
|
@@ -249,6 +249,62 @@ describe('SyntheticEvent', () => { | |
expect(expectedCount).toBe(1); | ||
}); | ||
|
||
it('should warn when calling `isPropagationStopped` if the synthetic event has not been persisted', () => { | ||
let node; | ||
let expectedCount = 0; | ||
let syntheticEvent; | ||
|
||
const eventHandler = e => { | ||
syntheticEvent = e; | ||
expectedCount++; | ||
}; | ||
node = ReactDOM.render(<div onClick={eventHandler} />, container); | ||
|
||
const event = document.createEvent('Event'); | ||
event.initEvent('click', true, true); | ||
node.dispatchEvent(event); | ||
|
||
expect(() => | ||
expect(syntheticEvent.isPropagationStopped()).toBe(false), | ||
).toWarnDev( | ||
'Warning: This synthetic event is reused for performance reasons. If ' + | ||
"you're seeing this, you're accessing the method `isPropagationStopped` on a " + | ||
'released/nullified synthetic event. This is a no-op function. If you must ' + | ||
'keep the original synthetic event around, use event.persist(). ' + | ||
'See https://fb.me/react-event-pooling for more information.', | ||
{withoutStack: true}, | ||
); | ||
expect(expectedCount).toBe(1); | ||
}); | ||
|
||
it('should warn when calling `isDefaultPrevented` if the synthetic event has not been persisted', () => { | ||
let node; | ||
let expectedCount = 0; | ||
let syntheticEvent; | ||
|
||
const eventHandler = e => { | ||
syntheticEvent = e; | ||
expectedCount++; | ||
}; | ||
node = ReactDOM.render(<div onClick={eventHandler} />, container); | ||
|
||
const event = document.createEvent('Event'); | ||
event.initEvent('click', true, true); | ||
node.dispatchEvent(event); | ||
|
||
expect(() => | ||
expect(syntheticEvent.isDefaultPrevented()).toBe(false), | ||
).toWarnDev( | ||
'Warning: This synthetic event is reused for performance reasons. If ' + | ||
"you're seeing this, you're accessing the method `isDefaultPrevented` on a " + | ||
'released/nullified synthetic event. This is a no-op function. If you must ' + | ||
'keep the original synthetic event around, use event.persist(). ' + | ||
'See https://fb.me/react-event-pooling for more information.', | ||
{withoutStack: true}, | ||
); | ||
expect(expectedCount).toBe(1); | ||
}); | ||
|
||
it('should properly log warnings when events simulated with rendered components', () => { | ||
let event; | ||
function assignEvent(e) { | ||
|
@@ -270,25 +326,25 @@ describe('SyntheticEvent', () => { | |
); | ||
}); | ||
|
||
it('should warn if Proxy is supported and the synthetic event is added a property', () => { | ||
// TODO: we might want to re-add a warning like this in the future, | ||
// but it shouldn't use Proxies because they making debugging difficult. | ||
// Or we might disallow this pattern altogether: | ||
// https://github.com/facebook/react/issues/13224 | ||
xit('should warn if synthetic event is added a property', () => { | ||
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. supernit "should warn if a property is added to a synthetic event" 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. Yeah, it already had the grammar issue before. Will do |
||
let node; | ||
let expectedCount = 0; | ||
let syntheticEvent; | ||
|
||
const eventHandler = e => { | ||
if (typeof Proxy === 'function') { | ||
expect(() => { | ||
e.foo = 'bar'; | ||
}).toWarnDev( | ||
'Warning: This synthetic event is reused for performance reasons. If ' + | ||
"you're seeing this, you're adding a new property in the synthetic " + | ||
'event object. The property is never released. ' + | ||
'See https://fb.me/react-event-pooling for more information.', | ||
{withoutStack: true}, | ||
); | ||
} else { | ||
expect(() => { | ||
e.foo = 'bar'; | ||
} | ||
}).toWarnDev( | ||
'Warning: This synthetic event is reused for performance reasons. If ' + | ||
"you're seeing this, you're adding a new property in the synthetic " + | ||
'event object. The property is never released. ' + | ||
'See https://fb.me/react-event-pooling for more information.', | ||
{withoutStack: true}, | ||
); | ||
syntheticEvent = e; | ||
expectedCount++; | ||
}; | ||
|
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.
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.
nit "they make debugging"