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 support for command invokers API #32480

Closed
wants to merge 1 commit into from

Conversation

lukewarlow
Copy link

Summary

Command Invokers are shipping in chrome soon and are now in the HTML spec, this adds support to React.

Fixes #32478

How did you test this change?

I've not yet the docs are out of date and refer to a UMD build that no longer exists.

@eps1lon
Copy link
Collaborator

eps1lon commented Feb 27, 2025

Awesome! Can you provide a fixture that illustrates their usage? You can use https://react.new/ and then specify builds from the ci/codesandbox check on this PR

@react-sizebot
Copy link

react-sizebot commented Feb 27, 2025

Comparing: aac177c...7ac0be1

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.js = 6.68 kB 6.68 kB = 1.83 kB 1.83 kB
oss-stable/react-dom/cjs/react-dom-client.production.js +0.08% 518.54 kB 518.95 kB +0.08% 92.45 kB 92.52 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 6.69 kB 6.69 kB = 1.83 kB 1.83 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js +0.07% 589.31 kB 589.71 kB +0.07% 104.91 kB 104.99 kB
facebook-www/ReactDOM-prod.classic.js +0.06% 642.76 kB 643.17 kB +0.07% 113.01 kB 113.08 kB
facebook-www/ReactDOM-prod.modern.js +0.06% 633.08 kB 633.49 kB +0.07% 111.44 kB 111.51 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against 7e636fd

@lukewarlow
Copy link
Author

lukewarlow commented Feb 27, 2025

https://codesandbox.io/p/sandbox/happy-wilbur-crtsz9 - So this will show the in-built commands work aswell as showing that custom ones work, but for some reason only onCommandCapture works, not onCommand?

I'm assuming I'm missing something in this PR to make onCommand work as expected. Though command events don't bubble so perhaps this is just due to React's synthetic events?

Btw this will only work in Chrome Canary with the experimental flag enabled right now. (It's shipping to stable 135)

@@ -3077,6 +3093,10 @@ export function hydrateProperties(
}
}

if (props.onCommand != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The target of these events won't be the element with the onCommand listener but the element that is the designated commandFor element. Not sure how to model that with our current event infrastructure. That doesn't explain why it doesn't work for commandFor="app" though.

Copy link
Author

Choose a reason for hiding this comment

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

That makes sense right? You do <div id="foo" onCommand={handle}><button commandFor="foo" command="--foobar">...</button> and clicking the button causes the browser to fire a (non-bubbling) command event on the foo div. That shouldn't need special handling in react right?

Copy link
Author

Choose a reason for hiding this comment

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

Though command events don't bubble, so I'm guessing I'm missing something somewhere to make the non capturing listener work with React's delegated event system?

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's why you have to attach the listener to the dom element referenced in commandFor not the one where we want to listen for command events.

@lukewarlow
Copy link
Author

I'm going to go ahead and close this. I frankly don't have the energy to deal with React's legacy event system. If anyone else wishes to pick this up feel free to, I'm happy to explain how the API works.

@lukewarlow lukewarlow closed this Mar 6, 2025
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.

Bug: Support command event
4 participants