Skip to content
Source
Sign inSign up
pingdotgg/t3code

perf(web): keep file lookup responsive while typing #11754

Closedsantekotturi(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/11754/headopened View on GitHub

Showing 2 changed files with 184 additions and 0 deletions (loading 1).

x
0 of 2 viewed, 2 left
184 additions and 0 deletionsapps/web/src/state/composerPathSearch.test.tsxAdded
View file
@@ -0,0 +1,184 @@
+import { EnvironmentId } from "@t3tools/contracts";
+import { act, useLayoutEffect, useMemo } from "react";
+import { create, type ReactTestRenderer } from "react-test-renderer";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
+​
+import { useComposerPathSearch } from "./queries";
+​
+const requests = vi.hoisted(() => ({
+ pending: new Set<string>(),
+ empty: new Set<string>(),
+ errors: new Set<string>(),
+ search: vi.fn(
+ (target: { environmentId: string; input: { cwd: string; query: string } }) => target,
+ ),
+}));
+vi.mock("./projects", () => ({
+ projectEnvironment: { searchEntries: requests.search },
+ projectContentSearch: vi.fn(),
+}));
+vi.mock("./query", () => ({
+ useEnvironmentQuery: (target: { input: { query: string } } | null) => {
+ const query = target?.input.query;
+ const pending = query !== undefined && requests.pending.has(query);
+ const error = query !== undefined && requests.errors.has(query) ? "Search failed" : null;
+ const empty = query !== undefined && requests.empty.has(query);
+ const data = useMemo(
+ () =>
+ query === undefined || pending || error
+ ? null
+ : {