Skip to content

Fixed Navigation: Create new Menu produces a warning in the console stating misuse of refs#68578

Open
Mayank-Tripathi32 wants to merge 1 commit intoWordPress:trunkfrom
Mayank-Tripathi32:try/fix-68572-console-error-disabled
Open

Fixed Navigation: Create new Menu produces a warning in the console stating misuse of refs#68578
Mayank-Tripathi32 wants to merge 1 commit intoWordPress:trunkfrom
Mayank-Tripathi32:try/fix-68572-console-error-disabled

Conversation

@Mayank-Tripathi32
Copy link
Contributor

fixes #68572

What?

Fix console warning about ref handling when creating a new menu from Navigation block's Block Panel in site editor

Why?

When creating a new menu from the Navigation block's Block Panel, a warning appears in the developer console: "Function components cannot be given refs". This warning occurs because the Disabled component, being a function component, cannot directly handle refs. This needs to be fixed to maintain a clean developer experience and proper component behavior.

How?

Modified the UnsavedInnerBlocks component to properly handle refs by:

  • Ensuring the ref from innerBlocksProps is passed to a DOM element (div) instead of the Disabled component
  • Wrapping the div with Disabled component when isSaving is true
  • Maintaining all other props and functionality from innerBlocksProps

Related React Issue

reactjs/react.dev#2120

Testing Instructions

  1. Navigate to the Site Editor
  2. Add a Navigation block
  3. Open the Block Panel (sidebar settings)
  4. Click the three dots menu
  5. Click "Create new Menu"
  6. Verify no warnings appear in the developer console
  7. Verify the menu creation functionality works as expected
  8. Verify the block's disabled state works correctly during saving

ScreenCast

TEST.NAVIGATION.CONSOLE.mp4

@github-actions
Copy link

github-actions bot commented Jan 9, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: Mayank-Tripathi32 <mayanktripathi32@git.wordpress.org>
Co-authored-by: yogeshbhutkar <yogeshbhutkar@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@t-hamano t-hamano added [Type] Code Quality Issues or PRs that relate to code quality [Block] Navigation Affects the Navigation Block labels Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Navigation Affects the Navigation Block [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Navigation: Create new Menu produces a warning in the console stating misuse of refs

2 participants