GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — perf(web): thread switches paint the timeline in their first frame (#… · pingdotgg/t3code@9b67169

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/web/src
    • components
      • ComposerPromptEditorTiptap.input.browser.test.tsx
      • ComposerPromptEditorTiptap.tsx
      • chat
        • useTallEnoughToFold.ts
      • pullRequest
        • PullRequestActionsMenu.browser.test.tsx
        • PullRequestActionsMenu.tsx
        • PullRequestBaseBranch.tsx
        • PullRequestDetailActions.tsx
        • PullRequestDetailCrumbs.tsx
        • PullRequestDetailLayout.tsx
        • PullRequestDetailPanel.tsx
        • PullRequestReactions.tsx
        • PullRequestStackHeader.tsx
        • PullRequestSummaryTab.browser.test.tsx
        • PullRequestSummaryTab.tsx
        • PullRequestThreadLinks.tsx
        • PullRequestTitleEditor.tsx
        • pullRequestDetail.logic.test.ts
        • pullRequestDetail.logic.ts
        • pullRequestPresentation.tsx
        • usePullRequestDetail.ts
      • sidebar
        • SidebarThreadRow.tsx
        • routeReveal.ts
        • useThreadIntentPrefetch.ts
      • ui
        • shared-tooltip.tsx
        • tooltip.browser.test.tsx
    • lib
      • preserveReadingPosition.ts
    • state
      • threads.ts
  • patches
    • @[email protected]
    • @[email protected]
    • [email protected]
  • pnpm-lock.yaml
  • pnpm-workspace.yaml
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/web/src/components/ComposerPromptEditorTiptap.input.browser.test.tsx‎

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 numberDiff line numberDiff line change
@@ -1281,7 +1281,10 @@ describe("composer context undo lifetime", () => {
12811281
const retained = composer.retained();
12821282
expect(retained.files.get(fileContextReference(file).contextId)?.file).toBe(file.file);
12831283

1284+
const editorBeforeSwitch = composer.editor();
12841285
await composer.show("b");
1286+
// Thread switches swap the draft into the same editor rather than rebuilding it.
1287+
expect(composer.editor()).toBe(editorBeforeSwitch);
12851288
expect(retained.files.size).toBe(0);
12861289
await composer.undo();
12871290
expect(serializeEditorDoc(composer.editor().state.doc).value).toBe(destinationValue);
Collapse file

‎apps/web/src/components/ComposerPromptEditorTiptap.tsx‎

Copy file name to clipboardExpand all lines: apps/web/src/components/ComposerPromptEditorTiptap.tsx
+34-7Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { useGT } from "gt-react";
2020
import { newlineInCode, splitBlockKeepMarks } from "@tiptap/pm/commands";
2121
import { isHistoryTransaction } from "@tiptap/pm/history";
2222
import {
23-
type EditorState,
23+
EditorState,
2424
NodeSelection,
2525
Plugin,
2626
PluginKey,
@@ -826,11 +826,12 @@ export function ComposerPromptEditorTiptap(props: ComposerPromptEditorProps) {
826826
setSelection({ value, cursor, expandedCursor });
827827
onPromptChange(value, cursor, expandedCursor, ...rest);
828828
};
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.
831832
return (
832833
<ComposerPromptEditorTiptapInner
833-
key={`${props.draftKey ?? ""}:${props.literalText ? "literal" : props.richTextEnabled ? "rich" : "plain"}`}
834+
key={props.literalText ? "literal" : props.richTextEnabled ? "rich" : "plain"}
834835
{...props}
835836
restoreFocusRef={restoreFocusRef}
836837
initialExpandedCursor={
@@ -1052,6 +1053,14 @@ function ComposerPromptEditorTiptapInner(
10521053
const [openCitation, setOpenCitation] = useState<OpenCitationComment | null>(null);
10531054
const citationDraftRef = useRef<{ key: string; comment: string } | null>(null);
10541055
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);
10551064

10561065
const citationCommentActions = {
10571066
openComment: openCitation,
@@ -1717,7 +1726,11 @@ function ComposerPromptEditorTiptapInner(
17171726
useLayoutEffect(() => {
17181727
latestValueRef.current = value;
17191728
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;
17211734
hasAppliedControlledSelectionRef.current = true;
17221735
const normalizedCursor = clampEditorCursor(value, cursor);
17231736
const previousSnapshot = snapshotRef.current;
@@ -1748,8 +1761,21 @@ function ComposerPromptEditorTiptapInner(
17481761

17491762
isApplyingControlledUpdateRef.current = true;
17501763
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) {
17531779
saveCitationDraft(editor, previousSnapshot.value);
17541780
editor.commands.setContent(
17551781
buildDocJson(value, skillLabelFor, { styling: richText, literalText, isKnownModel }),
@@ -1793,6 +1819,7 @@ function ComposerPromptEditorTiptapInner(
17931819
}, [
17941820
clampEditorCursor,
17951821
cursor,
1822+
draftKey,
17961823
editor,
17971824
expandEditorCursor,
17981825
initialExpandedCursor,
Collapse file

‎apps/web/src/components/chat/useTallEnoughToFold.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/components/chat/useTallEnoughToFold.ts
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ export function useTallEnoughToFold(enabled = true) {
1616
useLayoutEffect(() => {
1717
const content = ref.current;
1818
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;
2023
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+
});
2626
}, [enabled]);
2727
return { ref, tallEnough: enabled && tallEnough };
2828
}
Collapse file

‎apps/web/src/components/pullRequest/PullRequestActionsMenu.browser.test.tsx‎

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 numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ import { PullRequestActionsMenu } from "./PullRequestActionsMenu";
3737
const reference = { projectId: ProjectId.make("project"), repository: "owner/repo", number: 7 };
3838
const environmentId = EnvironmentId.make("environment");
3939

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 };
4142

4243
const openDetail: Detail = {
4344
url: "https://github.com/owner/repo/pull/7",
@@ -75,6 +76,7 @@ function setup() {
7576
reference={reference}
7677
pullRequestKey="owner/repo/7"
7778
detail={detail}
79+
observedAt={detail.observedAt}
7880
terminology={sourceControlClients.get("github").changeRequest}
7981
threadRef={null}
8082
linkThreadRef={null}
Collapse file

‎apps/web/src/components/pullRequest/PullRequestActionsMenu.tsx‎

Copy file name to clipboardExpand all lines: apps/web/src/components/pullRequest/PullRequestActionsMenu.tsx
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export function PullRequestActionsMenu({
7070
reference,
7171
pullRequestKey,
7272
detail,
73+
observedAt,
7374
terminology,
7475
threadRef,
7576
linkThreadRef,
@@ -121,8 +122,9 @@ export function PullRequestActionsMenu({
121122
| "capabilities"
122123
| "viewerPermissions"
123124
| "maintainerCanModify"
124-
| "observedAt"
125125
>;
126+
/** When the detail was last read; the detail itself keeps its older stamp across refreshes. */
127+
observedAt: number | undefined;
126128
terminology: ChangeRequestTerminology;
127129
threadRef: ScopedThreadRef | null;
128130
linkThreadRef: ScopedThreadRef | null;
@@ -179,7 +181,7 @@ export function PullRequestActionsMenu({
179181
const maintainerEditsChoiceKept = maintainerEditsChoiceInForce(
180182
maintainerEditsChoice,
181183
pullRequestKey,
182-
detail.observedAt,
184+
observedAt,
183185
maintainerEditsSaving,
184186
);
185187
if (maintainerEditsChoiceKept !== maintainerEditsChoice) {
@@ -191,7 +193,7 @@ export function PullRequestActionsMenu({
191193
const saveMaintainerEdits = async (value: boolean) => {
192194
if (!canSaveMaintainerEdits) return;
193195
const previousChoice = maintainerEditsChoice;
194-
setMaintainerEditsChoice({ key: pullRequestKey, observedAt: detail.observedAt, value });
196+
setMaintainerEditsChoice({ key: pullRequestKey, observedAt, value });
195197
setMaintainerEditsSaving(true);
196198
const result = await updatePullRequest({
197199
environmentId,
Collapse file

‎apps/web/src/components/pullRequest/PullRequestBaseBranch.tsx‎

Copy file name to clipboardExpand all lines: apps/web/src/components/pullRequest/PullRequestBaseBranch.tsx
+7-13Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { cn } from "~/lib/utils";
77
import { Button } from "../ui/button";
88
import { MiddleTruncate } from "../ui/middle-truncate";
99
import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
10-
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
10+
import { SharedTooltipTrigger } from "../ui/shared-tooltip";
1111
import { PullRequestGlyph } from "./pullRequestIcons";
1212

1313
interface BaseFreshness {
@@ -135,17 +135,11 @@ export function PullRequestBaseBranch({
135135
);
136136
}
137137
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+
/>
150144
);
151145
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.