Skip to content

Commit fa0d3bd

Browse files
perf(web): the HTML document frame compiles without manual memoization
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 70d60e0 commit fa0d3bd

2 files changed

Lines changed: 22 additions & 23 deletions

File tree

‎apps/web/reactCompiledFiles.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,5 @@ export const REACT_COMPILED_FILES = [
9696
"apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx",
9797
"apps/web/src/components/ThreadTerminalDrawer.tsx",
9898
"apps/web/src/components/settings/SettingsPanels.tsx",
99+
"apps/web/src/components/files/BrowserDocumentFrame.tsx",
99100
] as const;

‎apps/web/src/components/files/BrowserDocumentFrame.tsx‎

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
matchesKeybindingShortcut,
2323
normalizeEventKey,
2424
} from "@t3tools/shared/keybindings";
25-
import { useEffect, useEffectEvent, useLayoutEffect, useMemo, useRef, useState } from "react";
25+
import { useEffect, useEffectEvent, useLayoutEffect, useRef, useState } from "react";
2626

2727
import { useOpenLink } from "~/browser/useOpenLink";
2828
import { ExpandedImageDialog } from "~/components/chat/ExpandedImageDialog";
@@ -135,29 +135,27 @@ export function HtmlRenderDocument(props: {
135135
// binding counts whatever its `when`, and a key that any binding gives to
136136
// another command stays with the page. Only Cmd/Ctrl chords: a printable key
137137
// would type into the composer instead.
138-
const { shortcuts, blocked } = useMemo(() => {
139-
const mac = isMacPlatform(navigator.platform);
140-
const resolve = (shortcut: KeybindingShortcut): HtmlRenderShortcut => ({
141-
key: shortcut.key,
142-
metaKey: shortcut.metaKey || (shortcut.modKey && mac),
143-
ctrlKey: shortcut.ctrlKey || (shortcut.modKey && !mac),
144-
shiftKey: shortcut.shiftKey,
145-
altKey: shortcut.altKey,
146-
});
147-
const blocked = [...keybindings, ...(environmentKeybindings ?? [])]
148-
.filter((binding) => !HTML_RENDER_SHORTCUT_COMMANDS.has(binding.command))
149-
.map((binding) => resolve(binding.shortcut));
150-
const shortcuts = new Map<string, HtmlRenderShortcut>();
151-
for (const { command, shortcut } of keybindings) {
152-
if (
153-
HTML_RENDER_SHORTCUT_COMMANDS.has(command) &&
154-
(shortcut.metaKey || shortcut.ctrlKey || shortcut.modKey)
155-
) {
156-
shortcuts.set(shortcutConflictKey(shortcut), resolve(shortcut));
157-
}
138+
const mac = isMacPlatform(navigator.platform);
139+
const resolve = (shortcut: KeybindingShortcut): HtmlRenderShortcut => ({
140+
key: shortcut.key,
141+
metaKey: shortcut.metaKey || (shortcut.modKey && mac),
142+
ctrlKey: shortcut.ctrlKey || (shortcut.modKey && !mac),
143+
shiftKey: shortcut.shiftKey,
144+
altKey: shortcut.altKey,
145+
});
146+
const blocked = [...keybindings, ...(environmentKeybindings ?? [])]
147+
.filter((binding) => !HTML_RENDER_SHORTCUT_COMMANDS.has(binding.command))
148+
.map((binding) => resolve(binding.shortcut));
149+
const shortcutsByKey = new Map<string, HtmlRenderShortcut>();
150+
for (const { command, shortcut } of keybindings) {
151+
if (
152+
HTML_RENDER_SHORTCUT_COMMANDS.has(command) &&
153+
(shortcut.metaKey || shortcut.ctrlKey || shortcut.modKey)
154+
) {
155+
shortcutsByKey.set(shortcutConflictKey(shortcut), resolve(shortcut));
158156
}
159-
return { shortcuts: [...shortcuts.values()], blocked };
160-
}, [environmentKeybindings, keybindings]);
157+
}
158+
const shortcuts = [...shortcutsByKey.values()];
161159
const postShortcuts = () => {
162160
frameRef.current?.contentWindow?.postMessage(
163161
htmlRenderShortcutsMessage(shortcuts, blocked),

0 commit comments

Comments
 (0)