fix: early return in toolbar button to avoid unneeded calls to useInt…#24
fix: early return in toolbar button to avoid unneeded calls to useInt…#24
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughThe ChangesState Selection Refactoring
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🤖 Pull request artifacts
|
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/editor/plugins/block-toolbar-button/index.js (1)
65-65:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winTypo: "Reeset" → "Reset".
- // Reeset the popover mode when the popover closes. + // Reset the popover mode when the popover closes.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/editor/plugins/block-toolbar-button/index.js` at line 65, Fix the typo in the comment inside src/editor/plugins/block-toolbar-button/index.js: change "Reeset the popover mode when the popover closes." to "Reset the popover mode when the popover closes." so the inline comment above the popover-handling code (in the block-toolbar-button module) reads correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/editor/plugins/block-toolbar-button/index.js`:
- Around line 36-46: The conditional early-return after computing
hasAnchorAttribute causes hooks (useInteractions, useBlockHasInteraction,
useWithShift, useDispatch, the extra useState and useEffect calls) to be called
only when hasAnchorAttribute is true which breaks the Rules of Hooks; fix by
extracting the hook-using logic into a new inner component (e.g.,
BlockToolbarButtonInner) that accepts props and uses
isPopoverOpen/setIsPopoverOpen, useInteractions, useBlockHasInteraction,
useWithShift, useDispatch, and the useEffect hooks; keep the outer component to
only compute hasAnchorAttribute (using useSelect) and then return either
<BlockEdit {...props} /> when !hasAnchorAttribute or <BlockToolbarButtonInner
{...props} /> when true so hooks are called unconditionally within the inner
component; also correct the typo "Reeset" to "Reset".
---
Outside diff comments:
In `@src/editor/plugins/block-toolbar-button/index.js`:
- Line 65: Fix the typo in the comment inside
src/editor/plugins/block-toolbar-button/index.js: change "Reeset the popover
mode when the popover closes." to "Reset the popover mode when the popover
closes." so the inline comment above the popover-handling code (in the
block-toolbar-button module) reads correctly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b0d831ea-f083-4123-a16a-e30edce5c4c5
📒 Files selected for processing (1)
src/editor/plugins/block-toolbar-button/index.js
bfintal
left a comment
There was a problem hiding this comment.
The issue seems to be with the useInteractions hook, so let's fix the hook itself instead of returning early to avoid using the hook
…ditor re-renders and prevent Kadence inspector tab reset
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/editor/hooks/use-interactions.js`:
- Around line 256-258: The selector passed to useSelect (used to compute
interactionsFiltered) currently depends on the whole data object ([data])
causing unnecessary re-runs; change the dependency array to [data.interactions]
so the selector only re-evaluates when interactions actually change. Locate the
useSelect call that defines interactionsFiltered and update its dependency array
accordingly (the callback uses isInteractionShown and data.interactions).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 5401ae40-e7b7-410f-b1db-4b7be1448380
📒 Files selected for processing (1)
src/editor/hooks/use-interactions.js
…eractions
fixes #23
Summary by CodeRabbit