GeezerVison is showing github.com — perf(web): thread switches paint the timeline in their first frame (#… · pingdotgg/t3code@9b67169
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1281,7 +1281,10 @@ describe("composer context undo lifetime", () => { | 1281 | 1281 | const retained = composer.retained(); | 1282 | 1282 | expect(retained.files.get(fileContextReference(file).contextId)?.file).toBe(file.file); | 1283 | 1283 |
| | 1284 | + const editorBeforeSwitch = composer.editor(); | 1284 | 1285 | await composer.show("b"); | | 1286 | + // Thread switches swap the draft into the same editor rather than rebuilding it. | | 1287 | + expect(composer.editor()).toBe(editorBeforeSwitch); | 1285 | 1288 | expect(retained.files.size).toBe(0); | 1286 | 1289 | await composer.undo(); | 1287 | 1290 | expect(serializeEditorDoc(composer.editor().state.doc).value).toBe(destinationValue); | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/ComposerPromptEditorTiptap.tsx +34-7Lines changed: 34 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,7 +20,7 @@ import { useGT } from "gt-react"; | 20 | 20 | import { newlineInCode, splitBlockKeepMarks } from "@tiptap/pm/commands"; | 21 | 21 | import { isHistoryTransaction } from "@tiptap/pm/history"; | 22 | 22 | import { | 23 | | - type EditorState, | | 23 | + EditorState, | 24 | 24 | NodeSelection, | 25 | 25 | Plugin, | 26 | 26 | PluginKey, | @@ -826,11 +826,12 @@ export function ComposerPromptEditorTiptap(props: ComposerPromptEditorProps) { | 826 | 826 | setSelection({ value, cursor, expandedCursor }); | 827 | 827 | onPromptChange(value, cursor, expandedCursor, ...rest); | 828 | 828 | }; | 829 | | - // Changing text mode remounts the editor. Its collapsed cursor cannot represent | 830 | | - // a caret inside unknown `$name` text, so retain the exact Markdown offset here. | | 829 | + // Changing text mode remounts the editor; switching drafts reuses it (see the controlled-value | | 830 | + // effect). Its collapsed cursor cannot represent a caret inside unknown `$name` text, so retain | | 831 | + // the exact Markdown offset here. | 831 | 832 | return ( | 832 | 833 | <ComposerPromptEditorTiptapInner | 833 | | - key={`${props.draftKey ?? ""}:${props.literalText ? "literal" : props.richTextEnabled ? "rich" : "plain"}`} | | 834 | + key={props.literalText ? "literal" : props.richTextEnabled ? "rich" : "plain"} | 834 | 835 | {...props} | 835 | 836 | restoreFocusRef={restoreFocusRef} | 836 | 837 | initialExpandedCursor={ | @@ -1052,6 +1053,14 @@ function ComposerPromptEditorTiptapInner( | 1052 | 1053 | const [openCitation, setOpenCitation] = useState<OpenCitationComment | null>(null); | 1053 | 1054 | const citationDraftRef = useRef<{ key: string; comment: string } | null>(null); | 1054 | 1055 | const [isEmpty, setIsEmpty] = useState(value.length === 0); | | 1056 | + const draftKey = props.draftKey ?? ""; | | 1057 | + const [renderedDraftKey, setRenderedDraftKey] = useState(draftKey); | | 1058 | + if (renderedDraftKey !== draftKey) { | | 1059 | + setRenderedDraftKey(draftKey); | | 1060 | + setOpenCitation(null); | | 1061 | + setIsEmpty(value.length === 0); | | 1062 | + } | | 1063 | + const appliedDraftKeyRef = useRef(draftKey); | 1055 | 1064 |
| 1056 | 1065 | const citationCommentActions = { | 1057 | 1066 | openComment: openCitation, | @@ -1717,7 +1726,11 @@ function ComposerPromptEditorTiptapInner( | 1717 | 1726 | useLayoutEffect(() => { | 1718 | 1727 | latestValueRef.current = value; | 1719 | 1728 | if (!editor) return; | 1720 | | - const initialSelection = !hasAppliedControlledSelectionRef.current; | | 1729 | + // Switching threads swaps the draft in this same editor, which is far cheaper than rebuilding | | 1730 | + // it. A fresh state keeps undo from reaching back into the previous thread's draft. | | 1731 | + const draftChanged = appliedDraftKeyRef.current !== draftKey; | | 1732 | + appliedDraftKeyRef.current = draftKey; | | 1733 | + const initialSelection = !hasAppliedControlledSelectionRef.current || draftChanged; | 1721 | 1734 | hasAppliedControlledSelectionRef.current = true; | 1722 | 1735 | const normalizedCursor = clampEditorCursor(value, cursor); | 1723 | 1736 | const previousSnapshot = snapshotRef.current; | @@ -1748,8 +1761,21 @@ function ComposerPromptEditorTiptapInner( | 1748 | 1761 |
| 1749 | 1762 | isApplyingControlledUpdateRef.current = true; | 1750 | 1763 | const pendingCitation = | 1751 | | - citationRequestRef.current?.value === value ? citationRequestRef.current : null; | 1752 | | - if (previousSnapshot.value !== value) { | | 1764 | + !draftChanged && citationRequestRef.current?.value === value | | 1765 | + ? citationRequestRef.current | | 1766 | + : null; | | 1767 | + if (draftChanged) { | | 1768 | + citationRequestRef.current = null; | | 1769 | + citationDraftRef.current = null; | | 1770 | + editor.view.updateState( | | 1771 | + EditorState.create({ | | 1772 | + doc: editor.schema.nodeFromJSON( | | 1773 | + buildDocJson(value, skillLabelFor, { styling: richText, literalText, isKnownModel }), | | 1774 | + ), | | 1775 | + plugins: editor.state.plugins, | | 1776 | + }), | | 1777 | + ); | | 1778 | + } else if (previousSnapshot.value !== value) { | 1753 | 1779 | saveCitationDraft(editor, previousSnapshot.value); | 1754 | 1780 | editor.commands.setContent( | 1755 | 1781 | buildDocJson(value, skillLabelFor, { styling: richText, literalText, isKnownModel }), | @@ -1793,6 +1819,7 @@ function ComposerPromptEditorTiptapInner( | 1793 | 1819 | }, [ | 1794 | 1820 | clampEditorCursor, | 1795 | 1821 | cursor, | | 1822 | + draftKey, | 1796 | 1823 | editor, | 1797 | 1824 | expandEditorCursor, | 1798 | 1825 | initialExpandedCursor, | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/chat/useTallEnoughToFold.ts +6-6Lines changed: 6 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,13 +16,13 @@ export function useTallEnoughToFold(enabled = true) { | 16 | 16 | useLayoutEffect(() => { | 17 | 17 | const content = ref.current; | 18 | 18 | if (!enabled || !content) return; | 19 | | - const measure = () => { | | 19 | + // The observer reports after the browser's own layout and flushes before paint, so the first | | 20 | + // frame is already folded. Measuring here instead would force a layout mid-commit. | | 21 | + return observeResize(content, (entries) => { | | 22 | + const height = entries.at(-1)?.borderBoxSize[0]?.blockSize ?? content.offsetHeight; | 20 | 23 | const remPx = Number.parseFloat(getComputedStyle(document.documentElement).fontSize) || 16; | 21 | | - setTallEnough(content.offsetHeight >= FOLDED_HEIGHT_REM * 2 * remPx); | 22 | | - }; | 23 | | - // Measured here too: waiting for the observer would paint one unfolded frame. | 24 | | - measure(); | 25 | | - return observeResize(content, measure); | | 24 | + setTallEnough(height >= FOLDED_HEIGHT_REM * 2 * remPx); | | 25 | + }); | 26 | 26 | }, [enabled]); | 27 | 27 | return { ref, tallEnough: enabled && tallEnough }; | 28 | 28 | } |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/pullRequest/PullRequestActionsMenu.browser.test.tsx +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -37,7 +37,8 @@ import { PullRequestActionsMenu } from "./PullRequestActionsMenu"; | 37 | 37 | const reference = { projectId: ProjectId.make("project"), repository: "owner/repo", number: 7 }; | 38 | 38 | const environmentId = EnvironmentId.make("environment"); | 39 | 39 |
| 40 | | -type Detail = Parameters<typeof PullRequestActionsMenu>[0]["detail"]; | | 40 | +// Tests restamp the detail on each reading; the menu takes that stamp beside it. | | 41 | +type Detail = Parameters<typeof PullRequestActionsMenu>[0]["detail"] & { observedAt?: number }; | 41 | 42 |
| 42 | 43 | const openDetail: Detail = { | 43 | 44 | url: "https://github.com/owner/repo/pull/7", | @@ -75,6 +76,7 @@ function setup() { | 75 | 76 | reference={reference} | 76 | 77 | pullRequestKey="owner/repo/7" | 77 | 78 | detail={detail} | | 79 | + observedAt={detail.observedAt} | 78 | 80 | terminology={sourceControlClients.get("github").changeRequest} | 79 | 81 | threadRef={null} | 80 | 82 | linkThreadRef={null} | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/pullRequest/PullRequestActionsMenu.tsx +5-3Lines changed: 5 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -70,6 +70,7 @@ export function PullRequestActionsMenu({ | 70 | 70 | reference, | 71 | 71 | pullRequestKey, | 72 | 72 | detail, | | 73 | + observedAt, | 73 | 74 | terminology, | 74 | 75 | threadRef, | 75 | 76 | linkThreadRef, | @@ -121,8 +122,9 @@ export function PullRequestActionsMenu({ | 121 | 122 | | "capabilities" | 122 | 123 | | "viewerPermissions" | 123 | 124 | | "maintainerCanModify" | 124 | | - | "observedAt" | 125 | 125 | >; | | 126 | + /** When the detail was last read; the detail itself keeps its older stamp across refreshes. */ | | 127 | + observedAt: number | undefined; | 126 | 128 | terminology: ChangeRequestTerminology; | 127 | 129 | threadRef: ScopedThreadRef | null; | 128 | 130 | linkThreadRef: ScopedThreadRef | null; | @@ -179,7 +181,7 @@ export function PullRequestActionsMenu({ | 179 | 181 | const maintainerEditsChoiceKept = maintainerEditsChoiceInForce( | 180 | 182 | maintainerEditsChoice, | 181 | 183 | pullRequestKey, | 182 | | - detail.observedAt, | | 184 | + observedAt, | 183 | 185 | maintainerEditsSaving, | 184 | 186 | ); | 185 | 187 | if (maintainerEditsChoiceKept !== maintainerEditsChoice) { | @@ -191,7 +193,7 @@ export function PullRequestActionsMenu({ | 191 | 193 | const saveMaintainerEdits = async (value: boolean) => { | 192 | 194 | if (!canSaveMaintainerEdits) return; | 193 | 195 | const previousChoice = maintainerEditsChoice; | 194 | | - setMaintainerEditsChoice({ key: pullRequestKey, observedAt: detail.observedAt, value }); | | 196 | + setMaintainerEditsChoice({ key: pullRequestKey, observedAt, value }); | 195 | 197 | setMaintainerEditsSaving(true); | 196 | 198 | const result = await updatePullRequest({ | 197 | 199 | environmentId, | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/pullRequest/PullRequestBaseBranch.tsx +7-13Lines changed: 7 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,7 +7,7 @@ import { cn } from "~/lib/utils"; | 7 | 7 | import { Button } from "../ui/button"; | 8 | 8 | import { MiddleTruncate } from "../ui/middle-truncate"; | 9 | 9 | import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover"; | 10 | | -import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; | | 10 | +import { SharedTooltipTrigger } from "../ui/shared-tooltip"; | 11 | 11 | import { PullRequestGlyph } from "./pullRequestIcons"; | 12 | 12 |
| 13 | 13 | interface BaseFreshness { | @@ -135,17 +135,11 @@ export function PullRequestBaseBranch({ | 135 | 135 | ); | 136 | 136 | } | 137 | 137 | return ( | 138 | | - <Tooltip> | 139 | | - <TooltipTrigger | 140 | | - render={ | 141 | | - <span className="inline-flex min-w-0 max-w-[40%] shrink-0 items-center gap-1"> | 142 | | - {label} | 143 | | - </span> | 144 | | - } | 145 | | - /> | 146 | | - <TooltipPopup side="top"> | 147 | | - {stacked ? gt("Stacked on {baseBranch}", { baseBranch }) : baseBranch} | 148 | | - </TooltipPopup> | 149 | | - </Tooltip> | | 138 | + <SharedTooltipTrigger | | 139 | + render={ | | 140 | + <span className="inline-flex min-w-0 max-w-[40%] shrink-0 items-center gap-1">{label}</span> | | 141 | + } | | 142 | + label={stacked ? gt("Stacked on {baseBranch}", { baseBranch }) : baseBranch} | | 143 | + /> | 150 | 144 | ); | 151 | 145 | } |
|