fix: skip the first render so the anchor auto-generation only happens…#3651
fix: skip the first render so the anchor auto-generation only happens…#3651
Conversation
WalkthroughAdded a first-render guard in the heading block's edit component useEffect to skip timeout clearing and debounced anchor/text processing on initial render, deferring that logic to subsequent renders to avoid incorrect anchor propagation during duplication. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
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: 0
🧹 Nitpick comments (1)
src/block/heading/edit.js (1)
108-114: Type inconsistency inupdateTimeoutref usage.The guard works but reuses
updateTimeoutfor two purposes: a boolean flag on first render, then a timeout ID. On the second render,clearTimeout(true)is called—harmless but semantically incorrect.Consider using a separate ref for the mount check:
const [ prevText, setPrevText ] = useState( props.attributes.text ) const updateTimeout = useRef( null ) +const isFirstRender = useRef( true ) useEffect( () => { - // Use updateTimeout to skip effect on first render - if ( updateTimeout.current === null ) { - updateTimeout.current = true + if ( isFirstRender.current ) { + isFirstRender.current = false return } clearTimeout( updateTimeout.current )Alternatively, guard
clearTimeoutwith a type check:if ( typeof updateTimeout.current === 'number' ) { clearTimeout( updateTimeout.current ) }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/block/heading/edit.js(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: kaeizen
Repo: gambitph/Stackable PR: 3601
File: src/components/design-library-list/use-preview-renderer.js:307-331
Timestamp: 2025-09-25T08:17:15.564Z
Learning: In the design library preview renderer hook (src/components/design-library-list/use-preview-renderer.js), selectedTab changes trigger content updates through a chain of effects rather than direct dependencies. The first useEffect (template processing) responds to selectedTab changes indirectly and updates content state, which then triggers the second useEffect (rendering/scaling) that depends on content. This eliminates the need to add selectedTab to the second effect's dependency array.
📚 Learning: 2025-09-25T08:17:15.564Z
Learnt from: kaeizen
Repo: gambitph/Stackable PR: 3601
File: src/components/design-library-list/use-preview-renderer.js:307-331
Timestamp: 2025-09-25T08:17:15.564Z
Learning: In the design library preview renderer hook (src/components/design-library-list/use-preview-renderer.js), selectedTab changes trigger content updates through a chain of effects rather than direct dependencies. The first useEffect (template processing) responds to selectedTab changes indirectly and updates content state, which then triggers the second useEffect (rendering/scaling) that depends on content. This eliminates the need to add selectedTab to the second effect's dependency array.
Applied to files:
src/block/heading/edit.js
🧬 Code graph analysis (1)
src/block/heading/edit.js (1)
src/block/timeline/edit.js (1)
updateTimeout(134-134)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: PHP 7.3 and WP 6.5.5
- GitHub Check: PHP 8.2 and WP latest
- GitHub Check: PHP 7.3 and WP latest
- GitHub Check: PHP 8.2 and WP 6.7.2
- GitHub Check: PHP 8.2 and WP 6.6.2
- GitHub Check: PHP 8.2 and WP 6.5.5
- GitHub Check: build
🔇 Additional comments (1)
src/block/heading/edit.js (1)
117-125: Fix approach looks correct for the duplication issue.Skipping the first render prevents anchor auto-generation from running immediately after block duplication, which addresses issue #3297. The debounce logic and
__unstableMarkNextChangeAsNotPersistentusage are appropriate.
… onchange
fixes #3297, #3078
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.