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

[docs-infra] Simplify click header #42593

Merged
merged 1 commit into from
Jun 10, 2024

Conversation

oliviertassinari
Copy link
Member

@oliviertassinari oliviertassinari commented Jun 9, 2024

@oliviertassinari oliviertassinari added core Infrastructure work going on behind the scenes scope: docs-infra Specific to the docs-infra product labels Jun 9, 2024
@mui-bot
Copy link

mui-bot commented Jun 9, 2024

Netlify deploy preview

https://deploy-preview-42593--material-ui.netlify.app/

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against 44f05fa

Comment on lines -828 to +832
const elements = document.getElementsByClassName('title-link-to-anchor');
const elements = rootRef.current!.getElementsByClassName('title-link-to-anchor');
Copy link
Member Author

@oliviertassinari oliviertassinari Jun 9, 2024

Choose a reason for hiding this comment

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

The CSS is scoped to the component, so much better not to leak outside of this scope, especially since we bypass React here.

Comment on lines -833 to +837
elements[i].addEventListener('click', handleClick, false);
elements[i].addEventListener('click', handleHeaderClick);
Copy link
Member Author

@oliviertassinari oliviertassinari Jun 9, 2024

Choose a reason for hiding this comment

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

  • false is the default argument, no need
  • false is missing from the remove event handler, fix the removal logic
  • handleHeaderClick feels clearer

Comment on lines -835 to -840

return () => {
for (let i = 0; i < elements.length; i += 1) {
elements[i].removeEventListener('click', handleClick);
}
};
Copy link
Member Author

@oliviertassinari oliviertassinari Jun 9, 2024

Choose a reason for hiding this comment

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

If the component unmounts, these DOM nodes are removed. I imagine we don't need to remove event handlers. Even if the content is dynamic, removed DOM nodes would be gone, and elements[i].addEventListener('click', is smart, it deduplicates listeners if the arguments are identical (https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener), which is the case since handleClick is hoisted to the top level scope.


if (isRangeSelection) {
if (selection.type === 'Range') {
// Disable the <a> behavior to be able to select text.
Copy link
Member Author

Choose a reason for hiding this comment

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

We have this implicit rule to try to document each event.preventDefault(); call in the source because they tend to have strong implications, it's hard to not break stuff with them.

@alexfauquette alexfauquette merged commit e211fd8 into mui:next Jun 10, 2024
19 checks passed
@oliviertassinari oliviertassinari deleted the simplify-click-solution branch June 10, 2024 13:43
mnajdova pushed a commit to mnajdova/material-ui that referenced this pull request Jun 12, 2024
joserodolfofreitas pushed a commit to joserodolfofreitas/material-ui that referenced this pull request Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Infrastructure work going on behind the scenes scope: docs-infra Specific to the docs-infra product
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants