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

Fix #21972: Add onResize event to video elements #21973

Merged
merged 2 commits into from
Sep 7, 2021

Conversation

rileyjshaw
Copy link
Contributor

@rileyjshaw rileyjshaw commented Jul 27, 2021

Summary

This is a simple fix for #21972 that adds support for the onResize media event. See #21972 for a detailed description of the problem.

Test Plan

Pre-commit checklist (source)

✅ Fork the repository and create your branch from main.
✅ Run yarn in the repository root.
✅ If you’ve fixed a bug or added code that should be tested, add tests!
✅ Ensure the test suite passes (yarn test). Tip: yarn test --watch TestName is helpful in development.
✅ Run yarn test --prod to test in the production environment.
✅ If you need a debugger, run yarn debug-test --watch TestName, open chrome://inspect, and press “Inspect”.
✅ Format your code with prettier (yarn prettier).
✅ Make sure your code lints (yarn lint). Tip: yarn linc to only check changed files.
✅ Run the Flow typechecks (yarn flow).
✅ If you haven’t already, complete the CLA.

Post-commit checklist

The synthetic event reference docs will need to be updated.

This is a simple fix for facebook#21972 that adds support for the `onResize` media event.

I created a separate `videoEventTypes` array since I doubt anyone will want to add `onResize` to an audio event. It would simplify the code a bit to just add `resize` to the `mediaEventTypes` array, if that’s preferred.

Pre-commit checklist ([source](https://reactjs.org/docs/how-to-contribute.html#sending-a-pull-request))

✅ Fork the repository and create your branch from `main`.
✅ Run `yarn` in the repository root.
✅ If you’ve fixed a bug or added code that should be tested, add tests!
✅ Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch TestName` is helpful in development.
✅ Run `yarn test --prod` to test in the production environment.
✅ If you need a debugger, run `yarn debug-test --watch TestName`, open chrome://inspect, and press “Inspect”.
✅ Format your code with prettier (`yarn prettier`).
✅ Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only check changed files.
✅ Run the Flow typechecks (`yarn flow`).
✅ If you haven’t already, complete the CLA.
Comment on lines 204 to 205
// List of events that need to be individually attached to video elements.
export const videoEventTypes: Array<DOMEventName> = ['resize'];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: I created a separate videoEventTypes array, since I doubt anyone will want to add onResize to an audio event. It would simplify the code a bit to just add resize to the mediaEventTypes array, if that’s preferred.

Copy link
Collaborator

Choose a reason for hiding this comment

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

A one-item array seems like overkill to me. Are there any downsides to adding it to mediaEventTypes? I'd suggest that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy to make the change! The only “downside” is that since the resize event spec lists:

Media element is a video element

in its preconditions, we might want to log a warning if someone attaches onResize to an audio element. But I agree, I think the simplification is worth it. I’ll make the change now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done ✨

@sizebot
Copy link

sizebot commented Jul 27, 2021

Comparing: 8723932...5ec46b2

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js +0.08% 127.51 kB 127.62 kB +0.12% 40.68 kB 40.73 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js +0.08% 130.33 kB 130.44 kB +0.09% 41.63 kB 41.66 kB
facebook-www/ReactDOM-prod.classic.js +0.14% 407.35 kB 407.92 kB +0.08% 75.30 kB 75.36 kB
facebook-www/ReactDOM-prod.modern.js +0.14% 396.05 kB 396.62 kB +0.08% 73.55 kB 73.61 kB
facebook-www/ReactDOMForked-prod.classic.js +0.14% 407.35 kB 407.92 kB +0.08% 75.30 kB 75.36 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against 5ec46b2

@rileyjshaw
Copy link
Contributor Author

Bumping this in case nobody has seen it yet 👀

Copy link
Collaborator

@gaearon gaearon 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 a detailed PR. Unless there are good reasons, let's remove the second array and keep them unified.

Comment on lines 204 to 205
// List of events that need to be individually attached to video elements.
export const videoEventTypes: Array<DOMEventName> = ['resize'];
Copy link
Collaborator

Choose a reason for hiding this comment

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

A one-item array seems like overkill to me. Are there any downsides to adding it to mediaEventTypes? I'd suggest that.

@@ -216,6 +219,7 @@ export const nonDelegatedEvents: Set<DOMEventName> = new Set([
// and can occur on other elements too. Rather than duplicate that event,
// we just take it from the media events array.
...mediaEventTypes,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that adding resize here would disable delegation for it. Are there any existing cases where we relied on delegation for it? I suppose not because we used to warn, so it was definitely unused.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I can tell it was unused. Perhaps there could be a future conflict if a Synthetic Event was created for the Window:resize event?

It seems safe to me for now, but let me know if there are any further tests you’d like me to run.

@rileyjshaw
Copy link
Contributor Author

Thanks for the review, @gaearon! I consolidated the arrays as requested.

@gaearon gaearon merged commit fbce2d5 into facebook:main Sep 7, 2021
@gaearon
Copy link
Collaborator

gaearon commented Sep 7, 2021

Thanks!

@rileyjshaw rileyjshaw deleted the issue-21972 branch September 7, 2021 23:02
@gaearon gaearon mentioned this pull request Mar 29, 2022
zhengjitf pushed a commit to zhengjitf/react that referenced this pull request Apr 15, 2022
…21973)

* Fix facebook#21972: Add `onResize` event to video elements

This is a simple fix for facebook#21972 that adds support for the `onResize` media event.

I created a separate `videoEventTypes` array since I doubt anyone will want to add `onResize` to an audio event. It would simplify the code a bit to just add `resize` to the `mediaEventTypes` array, if that’s preferred.

Pre-commit checklist ([source](https://reactjs.org/docs/how-to-contribute.html#sending-a-pull-request))

✅ Fork the repository and create your branch from `main`.
✅ Run `yarn` in the repository root.
✅ If you’ve fixed a bug or added code that should be tested, add tests!
✅ Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch TestName` is helpful in development.
✅ Run `yarn test --prod` to test in the production environment.
✅ If you need a debugger, run `yarn debug-test --watch TestName`, open chrome://inspect, and press “Inspect”.
✅ Format your code with prettier (`yarn prettier`).
✅ Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only check changed files.
✅ Run the Flow typechecks (`yarn flow`).
✅ If you haven’t already, complete the CLA.

* Consolidate `videoEventTypes` array into `mediaEventTypes`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants