GeezerVison is showing github.com — fix(preview): preserve server-card routing · pingdotgg/t3code@57c59af
File treeExpand file treeCollapse file tree Open diff view settings apps/web/src/components/preview
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/preview/PreviewView.test.tsx +57-15Lines changed: 57 additions & 15 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -7,6 +7,8 @@ const mocks = vi.hoisted(() => ({ | 7 | 7 | rememberPreviewUrl: vi.fn(), | 8 | 8 | readPreparedConnection: vi.fn(() => ({ httpBaseUrl: "http://172.25.85.75:3773" })), | 9 | 9 | submittedUrl: null as ((url: string) => void) | null, | | 10 | + emptyStateUrl: null as ((url: string) => void) | null, | | 11 | + showEmptyState: false, | 10 | 12 | })); | 11 | 13 |
| 12 | 14 | vi.mock("~/state/session", () => ({ | @@ -42,20 +44,22 @@ vi.mock("~/previewStateStore", () => ({ | 42 | 44 | }, | 43 | 45 | }, | 44 | 46 | recentlySeenUrls: [], | 45 | | - sessions: { | 46 | | - "tab-1": { | 47 | | - threadId: "thread-1", | 48 | | - tabId: "tab-1", | 49 | | - navStatus: { | 50 | | - _tag: "Success", | 51 | | - url: "http://example.com/", | 52 | | - title: "Example", | | 47 | + sessions: mocks.showEmptyState | | 48 | + ? {} | | 49 | + : { | | 50 | + "tab-1": { | | 51 | + threadId: "thread-1", | | 52 | + tabId: "tab-1", | | 53 | + navStatus: { | | 54 | + _tag: "Success", | | 55 | + url: "http://example.com/", | | 56 | + title: "Example", | | 57 | + }, | | 58 | + canGoBack: false, | | 59 | + canGoForward: false, | | 60 | + updatedAt: "2026-07-13T00:00:00.000Z", | | 61 | + }, | 53 | 62 | }, | 54 | | - canGoBack: false, | 55 | | - canGoForward: false, | 56 | | - updatedAt: "2026-07-13T00:00:00.000Z", | 57 | | - }, | 58 | | - }, | 59 | 63 | }), | 60 | 64 | })); | 61 | 65 |
| @@ -100,7 +104,12 @@ vi.mock("./PreviewChromeRow", () => ({ | 100 | 104 | }, | 101 | 105 | })); | 102 | 106 |
| 103 | | -vi.mock("./PreviewEmptyState", () => ({ PreviewEmptyState: () => null })); | | 107 | +vi.mock("./PreviewEmptyState", () => ({ | | 108 | + PreviewEmptyState: (props: { onOpenUrl: (url: string) => void }) => { | | 109 | + mocks.emptyStateUrl = props.onOpenUrl; | | 110 | + return null; | | 111 | + }, | | 112 | +})); | 104 | 113 | vi.mock("./PreviewMoreMenu", () => ({ PreviewMoreMenu: () => null })); | 105 | 114 | vi.mock("./PreviewUnreachable", () => ({ PreviewUnreachable: () => null })); | 106 | 115 | vi.mock("./ZoomIndicator", () => ({ ZoomIndicator: () => null })); | @@ -111,12 +120,14 @@ vi.mock("./usePreviewSession", () => ({ usePreviewSession: vi.fn() })); | 111 | 120 |
| 112 | 121 | import { PreviewView } from "./PreviewView"; | 113 | 122 |
| 114 | | -describe("PreviewView address bar", () => { | | 123 | +describe("PreviewView navigation", () => { | 115 | 124 | beforeEach(() => { | 116 | 125 | mocks.navigate.mockClear(); | 117 | 126 | mocks.rememberPreviewUrl.mockClear(); | 118 | 127 | mocks.readPreparedConnection.mockClear(); | 119 | 128 | mocks.submittedUrl = null; | | 129 | + mocks.emptyStateUrl = null; | | 130 | + mocks.showEmptyState = false; | 120 | 131 | }); | 121 | 132 |
| 122 | 133 | it("preserves a direct localhost URL in a WSL environment", async () => { | @@ -148,4 +159,35 @@ describe("PreviewView address bar", () => { | 148 | 159 | "https://localhost:8000/dashboard?mode=test#top", | 149 | 160 | ); | 150 | 161 | }); | | 162 | + | | 163 | + it("maps an empty-state localhost server onto the WSL host", async () => { | | 164 | + mocks.showEmptyState = true; | | 165 | + renderToStaticMarkup( | | 166 | + <PreviewView | | 167 | + threadRef={{ | | 168 | + environmentId: EnvironmentId.make("environment-1"), | | 169 | + threadId: ThreadId.make("thread-1"), | | 170 | + }} | | 171 | + tabId="tab-1" | | 172 | + visible | | 173 | + />, | | 174 | + ); | | 175 | + | | 176 | + expect(mocks.emptyStateUrl).not.toBeNull(); | | 177 | + mocks.emptyStateUrl?.("http://localhost:5173/app?mode=test#top"); | | 178 | + | | 179 | + await vi.waitFor(() => | | 180 | + expect(mocks.navigate).toHaveBeenCalledWith( | | 181 | + "tab-1", | | 182 | + "http://172.25.85.75:5173/app?mode=test#top", | | 183 | + ), | | 184 | + ); | | 185 | + expect(mocks.rememberPreviewUrl).toHaveBeenCalledWith( | | 186 | + { | | 187 | + environmentId: "environment-1", | | 188 | + threadId: "thread-1", | | 189 | + }, | | 190 | + "http://172.25.85.75:5173/app?mode=test#top", | | 191 | + ); | | 192 | + }); | 151 | 193 | }); |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/preview/PreviewView.tsx +10-2Lines changed: 10 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,7 +17,10 @@ import { | 17 | 17 | updatePreviewServerSnapshot, | 18 | 18 | useThreadPreviewState, | 19 | 19 | } from "~/previewStateStore"; | 20 | | -import { resolveBrowserNavigationTarget } from "~/browser/browserTargetResolver"; | | 20 | +import { | | 21 | + resolveBrowserNavigationTarget, | | 22 | + resolveDiscoveredServerUrl, | | 23 | +} from "~/browser/browserTargetResolver"; | 21 | 24 | import { useEnvironment, useEnvironmentHttpBaseUrl } from "~/state/environments"; | 22 | 25 | import { previewEnvironment } from "~/state/preview"; | 23 | 26 | import { useAtomCommand } from "~/state/use-atom-command"; | @@ -138,6 +141,11 @@ export function PreviewView({ threadRef, tabId: requestedTabId, configuredUrls, | 138 | 141 | [open, tabId, threadRef], | 139 | 142 | ); | 140 | 143 |
| | 144 | + const handleOpenServerUrl = useCallback( | | 145 | + (next: string) => handleSubmitUrl(resolveDiscoveredServerUrl(threadRef.environmentId, next)), | | 146 | + [handleSubmitUrl, threadRef.environmentId], | | 147 | + ); | | 148 | + | 141 | 149 | const handleRefresh = useCallback(() => { | 142 | 150 | if (previewBridge && tabId) void previewBridge.refresh(tabId); | 143 | 151 | }, [tabId]); | @@ -616,7 +624,7 @@ export function PreviewView({ threadRef, tabId: requestedTabId, configuredUrls, | 616 | 624 | environmentId={threadRef.environmentId} | 617 | 625 | configuredUrls={configuredUrls} | 618 | 626 | recentlySeenUrls={previewState.recentlySeenUrls} | 619 | | - onOpenUrl={(next) => void handleSubmitUrl(next)} | | 627 | + onOpenUrl={(next) => void handleOpenServerUrl(next)} | 620 | 628 | /> | 621 | 629 | ) : null} | 622 | 630 | {snapshot && desktopOverlay ? ( | |
|