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] Fix element.ref accessing warning on docs #45155

Merged
merged 2 commits into from
Feb 4, 2025

Conversation

DiegoAndai
Copy link
Member

Problem

Fix this warning (only visible on local):

Screenshot 2025-01-30 at 16 26 04

To repro, simply checkout master, run docs and visit the homepage.

Solution

Remove the usage of legacyBehavior on the docs' Link component (source). This legacy behavior relies on accessing the child ref, causing the warning:

https://github.com/vercel/next.js/blob/38a6d0177eced9b56dfcc58f83662a659195af15/packages/next/src/client/link.tsx#L461

Here's the guide on removing this prop: vercel/next.js@489e65e.

I think we can remove it as the only thing we're doing on NextLinkComposed is adding an empty styled anchor, which Next's Link now does by default:

https://github.com/vercel/next.js/blob/38a6d0177eced9b56dfcc58f83662a659195af15/packages/next/src/client/link.tsx#L621-L623

So:

  • For usages with legacyBehavior = true, the result is the same
  • There shouldn't be any usages with legacyBehavior = false, as that would result in a nested anchor which is not valid HTML. I searched confirmed this in this repo, MUI X's, and Toolpad's.

Note: I updated the pages router examples accordingly.

@DiegoAndai DiegoAndai added docs Improvements or additions to the documentation core Infrastructure work going on behind the scenes labels Jan 30, 2025
@DiegoAndai DiegoAndai requested a review from Janpot January 30, 2025 19:37
@DiegoAndai DiegoAndai self-assigned this Jan 30, 2025
@mui-bot
Copy link

mui-bot commented Jan 30, 2025

Netlify deploy preview

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

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against 9dc2253

Copy link
Member

@Janpot Janpot left a comment

Choose a reason for hiding this comment

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

Should be fine. I don't expect anyone cloning these examples with the intent of using the legacy behavior.

@DiegoAndai DiegoAndai merged commit 70e8ed0 into mui:master Feb 4, 2025
24 checks passed
@DiegoAndai DiegoAndai deleted the fix-ref-accessing-warning-on-docs branch February 4, 2025 12:35
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 docs Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants