Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion components/CommandPalette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ export function CommandPalette() {

// Auto-scroll the active option into view for keyboard navigation (#651).
useEffect(() => {
itemRefs.current[activeIndex]?.scrollIntoView({ block: "nearest" });
const activeItem = itemRefs.current[activeIndex];
if (activeItem && typeof activeItem.scrollIntoView === "function") {
activeItem.scrollIntoView({ block: "nearest" });
}
}, [activeIndex, open, query]);

// Global Escape dismissal so the palette closes even when focus is not
Expand Down
6 changes: 3 additions & 3 deletions components/NetworkLatencyIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function NetworkLatencyIndicator() {
if (!rpcUrl) return;

abortController = new AbortController();
const started = typeof performance !== 'undefined' ? performance.now() : Date.now();
const started = Date.now();

try {
const res = await fetch(rpcUrl, {
Expand All @@ -39,8 +39,8 @@ export function NetworkLatencyIndicator() {
body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'getLatestLedger' }),
signal: abortController.signal,
});
const ended = typeof performance !== 'undefined' ? performance.now() : Date.now();
const latencyMs = Math.round(ended - started);
const ended = Date.now();
const latencyMs = Math.max(0, Math.round(ended - started));

let ledgerHeight: number | null = null;
if (res.ok) {
Expand Down
6 changes: 3 additions & 3 deletions components/__tests__/NetworkLatencyIndicator.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ describe('NetworkLatencyIndicator', () => {
} as Response;
});

const perfSpy = vi.spyOn(performance, 'now');
perfSpy.mockReturnValueOnce(1000).mockReturnValueOnce(3500);
const dateSpy = vi.spyOn(Date, 'now');
dateSpy.mockReturnValueOnce(1000).mockReturnValueOnce(3500);

await act(async () => {
root.render(React.createElement(NetworkLatencyIndicator));
Expand All @@ -67,7 +67,7 @@ describe('NetworkLatencyIndicator', () => {
expect(pill?.className).toContain('text-amber-700');
expect(container.textContent).toContain('2500ms');

perfSpy.mockRestore();
dateSpy.mockRestore();
mockFetch.mockRestore();
});

Expand Down