@devries-cameron20 / t3code Mirror · read-only / commits / 1c99a55444
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 12:00 UTC

fix(web): report invalid preview addresses (#23577)

Co-authored-by: GPT-6.1 Sol <noreply@openai.com>

Victor Vogel committed Oct 30, 2026 at 15:53 UTC 1c99a55444b6a03ec6a056a99a44131f3e1d13fb
2 files changed +41 -7
apps/web/src/components/preview/PreviewView.browser.test.tsx
+18 -5
@@ -28,7 +28,6 @@ const mocks = vi.hoisted(() => ({
28 pickElement: vi.fn(),
29 addPreviewAnnotation: vi.fn(),
30 addImage: vi.fn(),
31 - toast: vi.fn(),
31 pictureInPicture: false,
32 showEmptyState: false,
33 loading: false,
@@ -136,10 +135,6 @@ vi.mock(import("~/browser/browserRecording"), async (original) => ({
135 findActiveBrowserRecordingRuntimeTabId: () => mocks.recordingRuntimeTabId,
136 useActiveBrowserRecordingTabIds: () => mocks.recordingTabIds,
137 }));
139 -vi.mock(import("~/components/ui/toast"), async (original) => {
140 - const actual = await original();
141 - return { ...actual, toastManager: { ...actual.toastManager, add: mocks.toast } };
142 -});
138 vi.mock(import("./useDiscoveredLocalServers"), async (original) => ({
139 ...(await original()),
140 useDiscoveredLocalServers: () => mocks.servers,
@@ -162,6 +157,7 @@ import { previewRuntimeTabId } from "~/browser/previewRuntimeTabId";
157 import { usePreviewMiniPlayerStore } from "~/previewMiniPlayerStore";
158 import { dispatchPreviewAction } from "./previewActionBus";
159 import { PreviewView } from "./PreviewView";
160 +import { ToastProvider } from "~/components/ui/toast";
161
162 const TEST_THREAD_REF = {
163 environmentId: EnvironmentId.make("environment-1"),
@@ -219,6 +215,23 @@ function setup() {
215 }
216
217 describe("PreviewView", () => {
218 + it.each(["mailto:alice@example.com", "http://"])(
219 + "reports rejected address %s without navigating or recording it",
220 + async (address) => {
221 + setup();
222 + await using _screen = await render(<ToastProvider timeout={0}>{view()}</ToastProvider>);
223 + const input = page.getByPlaceholder("Search or enter URL");
224 + await input.fill(address);
225 + await userEvent.keyboard("{Enter}");
226 +
227 + await expect.element(page.getByText("Could not open this address")).toBeVisible();
228 + await expect.element(page.getByText("Enter an http or https URL.")).toBeVisible();
229 + expect(mocks.navigate).not.toHaveBeenCalled();
230 + expect(mocks.recordVisitForThread).not.toHaveBeenCalled();
231 + await userEvent.click(page.getByRole("button", { name: "Dismiss notification" }));
232 + },
233 + );
234 +
235 it("retains the annotation locally when its own environment loses access during capture", async () => {
236 setup();
237 const picked = annotation("annotation-revoked");
apps/web/src/components/preview/PreviewView.tsx
+23 -2
@@ -17,6 +17,7 @@ import {
17 } from "@t3tools/contracts";
18 import {
19 normalizePreviewUrl,
20 + isPreviewUrlNormalizationError,
21 resolveAddressBarInput,
22 previewPdfAssetUrl,
23 resolveSearchUrlTemplate,
@@ -259,7 +260,17 @@ export function PreviewView({
260 if (await navigateToResolvedUrl(resolved)) {
261 recordVisitForThread(threadRef, resolved);
262 }
262 - } catch {}
263 + } catch (error) {
264 + toastManager.add({
265 + type: "error",
266 + title: "Could not open this address",
267 + description: isPreviewUrlNormalizationError(error)
268 + ? "Enter an http or https URL."
269 + : error instanceof Error
270 + ? error.message
271 + : "An error occurred.",
272 + });
273 + }
274 };
275
276 const handleOpenServerUrl = async (next: string) => {
@@ -271,7 +282,17 @@ export function PreviewView({
282 if (await navigateToResolvedUrl(resolved)) {
283 recordVisitForThread(threadRef, next);
284 }
274 - } catch {}
285 + } catch (error) {
286 + toastManager.add({
287 + type: "error",
288 + title: "Could not open this address",
289 + description: isPreviewUrlNormalizationError(error)
290 + ? "Enter an http or https URL."
291 + : error instanceof Error
292 + ? error.message
293 + : "An error occurred.",
294 + });
295 + }
296 };
297
298 const handleRefresh = () => {