Skip to content

Commit

Permalink
Fix missing frame when dissolving
Browse files Browse the repository at this point in the history
  • Loading branch information
zukilover committed Dec 24, 2024
1 parent 81ca9f1 commit 7859290
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
6 changes: 1 addition & 5 deletions src/components/LayoutTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,6 @@ const TreeNode = ({
const lastPatches = state.undoPatches[state.undoPatches.length - 1]
return lastPatches?.some(patch => patch.actions[0] === 'newThought')
})
const isLastActionDeleteThought = useSelector(state => {
const lastPatches = state.undoPatches[state.undoPatches.length - 1]
return lastPatches?.some(patch => patch.actions[0] === 'deleteThoughtWithCursor')
})

useLayoutEffect(() => {
if (y !== _y) {
Expand Down Expand Up @@ -493,7 +489,7 @@ const TreeNode = ({
// The FadeTransition is only responsible for fade out on unmount;
// or for fade in on mounting of a new thought.
// See autofocusChanged for normal opacity transition.
duration={isEmpty ? 'nodeFadeIn' : isLastActionDeleteThought ? 'nodeDissolve' : 'nodeFadeOut'}
duration={isEmpty ? 'nodeFadeIn' : 'nodeDissolve'}
nodeRef={fadeThoughtRef}
in={transitionGroupsProps.in}
unmountOnExit
Expand Down
20 changes: 18 additions & 2 deletions src/components/Subthought.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,28 @@ const Subthought = ({
ref.current.style.opacity = opacity
})

/**
* Cleans up editable classes from the provided HTML string.
*
* @param htmlString - The HTML string to clean up.
* @returns The cleaned HTML string.
*/
const cleanUpEditableClasses = (htmlString: string) => {
const container = document.createElement('div')
container.innerHTML = htmlString
const editableElements = container.querySelectorAll('.editable--preventAutoscroll_true')
editableElements.forEach(element => {
element.classList.remove('editable--preventAutoscroll_true')
})
return container.innerHTML
}

// Capture the static HTML string when the thought is first rendered
useEffect(() => {
if (thought && ref.current) {
cachedHTMLRef.current = ref.current.innerHTML
cachedHTMLRef.current = cleanUpEditableClasses(ref.current.innerHTML)
}
}, [thought])
}, [thought, ref])

// If the thought is deleted, return the cached static HTML from the ref
if (!thought && cachedHTMLRef.current) {
Expand Down

0 comments on commit 7859290

Please sign in to comment.