-
Notifications
You must be signed in to change notification settings - Fork 0
fix/14 editor show template #15
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
base: develop
Are you sure you want to change the base?
Conversation
…hanged id; wait for anchor tracking
📝 WalkthroughWalkthroughIntroduces rendering-mode–aware initialization and persistent starting styles in the timeline runner hook, and refactors anchor tracking to remove duplicates by tracking the previous anchor reference and cleaning up accordingly. Changes
Sequence Diagram(s)sequenceDiagram
participant Hook as useTimelineRunnerRef
participant Store as WP Data Store
participant RAF as requestAnimationFrame
participant Runner as Runner/init logic
participant Anchors as Anchor replacements
Hook->>Store: read renderingMode
alt renderingMode changed
Hook->>RAF: requestAnimationFrame(callback)
RAF-->>Hook: callback
Hook->>Anchors: replace anchors
Hook->>Runner: configure & init
Runner-->>Hook: starting styles
else renderingMode unchanged
Hook->>Anchors: replace anchors
Hook->>Runner: configure & init
Runner-->>Hook: starting styles
end
Hook-->>Hook: set initialStyles state
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@src/editor/components/timeline/runner.js`:
- Around line 67-76: The current code returns
runnerRef.current.getStartingActionStyles() synchronously even when initRunner
is deferred, producing stale/empty styles; move the renderingMode change
handling out of this synchronous block into a useEffect that watches
renderingMode and calls initRunner (using setTimeout if needed), then update
local state (e.g., startingStyles) or trigger a re-render when initRunner
completes; change the return to read from that state (instead of calling
getStartingActionStyles() directly) so styles are computed after initRunner
finishes—refer to initRunner, prevRenderingMode.current, renderingMode, and
runnerRef.current.getStartingActionStyles when locating where to apply this
change.
In `@src/editor/components/timeline/with-tracked-anchors.js`:
- Around line 15-43: The effect is missing cleanup and skips removing a previous
anchor when the current anchor becomes undefined; update the useEffect
(referencing useEffect, prevAnchorRef.current, ANCHORS, CLIENT_IDS,
props.clientId, props.attributes?.anchor) so that before the early return you
still remove any prevAnchorRef.current entry from ANCHORS/CLIENT_IDS, and return
a cleanup function that removes the current anchor (or prevAnchorRef.current if
undefined) from ANCHORS and CLIENT_IDS on unmount to avoid stale entries; ensure
you update prevAnchorRef.current appropriately after removals.
🧹 Nitpick comments (1)
src/editor/components/timeline/runner.js (1)
70-70: Consider cleanup for the setTimeout.If the component re-renders or unmounts before the timeout fires,
initRunnerwould still execute with potentially stale references. Consider storing the timeout ID and clearing it on cleanup or subsequent renders.Suggestion using a ref to track timeout
const runnerRef = useRef( null ) + const initTimeoutRef = useRef( null ) const renderingMode = select( 'core/editor' ).getRenderingMode() const prevRenderingMode = useRef( renderingMode )Then in the useMemo:
if ( prevRenderingMode.current !== renderingMode ) { + if ( initTimeoutRef.current ) { + clearTimeout( initTimeoutRef.current ) + } - setTimeout( initRunner, 0 ) + initTimeoutRef.current = setTimeout( initRunner, 0 ) } else {
| useEffect( () => { | ||
| if ( props.attributes.anchor ) { | ||
| // Remove any previous anchor selector for this clientId. | ||
| const index = CLIENT_IDS.indexOf( props.clientId ) | ||
| if ( index !== -1 ) { | ||
| CLIENT_IDS.splice( index, 1 ) | ||
| ANCHORS.splice( index, 1 ) | ||
| const anchor = props.attributes?.anchor | ||
| if ( ! anchor ) { | ||
| return | ||
| } | ||
|
|
||
| // If this block had a previous anchor, remove it. | ||
| if ( prevAnchorRef.current ) { | ||
| const oldIndex = ANCHORS.indexOf( prevAnchorRef.current ) | ||
| if ( oldIndex !== -1 ) { | ||
| ANCHORS.splice( oldIndex, 1 ) | ||
| CLIENT_IDS.splice( oldIndex, 1 ) | ||
| } | ||
| // Keep track of the clientId-anchor pair | ||
| CLIENT_IDS.push( props.clientId ) | ||
| ANCHORS.push( props.attributes.anchor ) | ||
| } | ||
| }, [ | ||
| props.clientId, | ||
| props.attributes?.anchor, | ||
| ] ) | ||
|
|
||
| // Remove any existing entry for this anchor. | ||
| // This ensures no duplication when the blocks are re-rendered. | ||
| const existingIndex = ANCHORS.indexOf( anchor ) | ||
| if ( existingIndex !== -1 ) { | ||
| ANCHORS.splice( existingIndex, 1 ) | ||
| CLIENT_IDS.splice( existingIndex, 1 ) | ||
| } | ||
|
|
||
| ANCHORS.push( anchor ) | ||
| CLIENT_IDS.push( props.clientId ) | ||
|
|
||
| // Store anchor for next render | ||
| prevAnchorRef.current = anchor | ||
| }, [ props.clientId, props.attributes?.anchor ] ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing cleanup on unmount and when anchor is removed.
Two issues with the effect:
-
No cleanup function: When the component unmounts, the anchor entry remains in the global arrays, causing stale data.
-
Early return doesn't clean up previous anchor: If an anchor is removed from a block (becomes undefined), the early return at line 17-19 skips removing the old entry stored in
prevAnchorRef.current.
Proposed fix
useEffect( () => {
const anchor = props.attributes?.anchor
+
+ // If anchor was removed, clean up the previous entry
if ( ! anchor ) {
+ if ( prevAnchorRef.current ) {
+ const oldIndex = ANCHORS.indexOf( prevAnchorRef.current )
+ if ( oldIndex !== -1 ) {
+ ANCHORS.splice( oldIndex, 1 )
+ CLIENT_IDS.splice( oldIndex, 1 )
+ }
+ prevAnchorRef.current = undefined
+ }
return
}
// If this block had a previous anchor, remove it.
if ( prevAnchorRef.current ) {
const oldIndex = ANCHORS.indexOf( prevAnchorRef.current )
if ( oldIndex !== -1 ) {
ANCHORS.splice( oldIndex, 1 )
CLIENT_IDS.splice( oldIndex, 1 )
}
}
// Remove any existing entry for this anchor.
// This ensures no duplication when the blocks are re-rendered.
const existingIndex = ANCHORS.indexOf( anchor )
if ( existingIndex !== -1 ) {
ANCHORS.splice( existingIndex, 1 )
CLIENT_IDS.splice( existingIndex, 1 )
}
ANCHORS.push( anchor )
CLIENT_IDS.push( props.clientId )
// Store anchor for next render
prevAnchorRef.current = anchor
+
+ // Cleanup on unmount
+ return () => {
+ const index = ANCHORS.indexOf( anchor )
+ if ( index !== -1 ) {
+ ANCHORS.splice( index, 1 )
+ CLIENT_IDS.splice( index, 1 )
+ }
+ }
}, [ props.clientId, props.attributes?.anchor ] )🤖 Prompt for AI Agents
In `@src/editor/components/timeline/with-tracked-anchors.js` around lines 15 - 43,
The effect is missing cleanup and skips removing a previous anchor when the
current anchor becomes undefined; update the useEffect (referencing useEffect,
prevAnchorRef.current, ANCHORS, CLIENT_IDS, props.clientId,
props.attributes?.anchor) so that before the early return you still remove any
prevAnchorRef.current entry from ANCHORS/CLIENT_IDS, and return a cleanup
function that removes the current anchor (or prevAnchorRef.current if undefined)
from ANCHORS and CLIENT_IDS on unmount to avoid stale entries; ensure you update
prevAnchorRef.current appropriately after removals.
fixes #14
Observations:
Issues:
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.