diff --git a/apps/docs/app/(diffs)/playground/PlaygroundCodeView.tsx b/apps/docs/app/(diffs)/playground/PlaygroundCodeView.tsx index 813a0f88e..8c43c5a6a 100644 --- a/apps/docs/app/(diffs)/playground/PlaygroundCodeView.tsx +++ b/apps/docs/app/(diffs)/playground/PlaygroundCodeView.tsx @@ -17,6 +17,7 @@ import { type CodeViewReactOptions, useStableCallback, } from '@pierre/diffs/react'; +import { IconCheckboxFill, IconSquircleLg } from '@pierre/icons'; import { useCallback, useEffect, useMemo, useState } from 'react'; import { flushSync } from 'react-dom'; @@ -390,16 +391,30 @@ export function PlaygroundCodeView({ ); const renderHeaderMetadata = useStableCallback((item: PlaygroundItem) => { + const isEditing = item.edit === true; return ( - + ); }); diff --git a/apps/docs/app/(diffs)/playground/PlaygroundVirtualizerElementView.tsx b/apps/docs/app/(diffs)/playground/PlaygroundVirtualizerElementView.tsx index d9a54e6ef..364ec52c0 100644 --- a/apps/docs/app/(diffs)/playground/PlaygroundVirtualizerElementView.tsx +++ b/apps/docs/app/(diffs)/playground/PlaygroundVirtualizerElementView.tsx @@ -10,6 +10,7 @@ import { } from '@pierre/diffs'; import type { EditorOptions } from '@pierre/diffs/editor'; import { FileDiff, useStableCallback, Virtualizer } from '@pierre/diffs/react'; +import { IconCheckboxFill, IconSquircleLg } from '@pierre/icons'; import { useCallback, useEffect, useMemo, useState } from 'react'; import { flushSync } from 'react-dom'; @@ -219,19 +220,30 @@ function ElementVirtualizerDiff({ } ); - const renderHeaderMetadata = useStableCallback(() => { + // Must NOT be a stable callback: FileDiff invokes renderHeaderMetadata + // synchronously during render, but useStableCallback only refreshes its inner + // ref in a commit-phase insertion effect. Reading `editing` (render-phase + // state) through a stable wrapper would render the button one toggle behind — + // the header would reflect the previous `editing` value. A per-`editing` + // useCallback hands renderDiffChildren the current closure each toggle. + const renderHeaderMetadata = useCallback(() => { return ( -