Skip to content
Closed
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
7 changes: 4 additions & 3 deletions apps/web/src/browser/openFileInPreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export async function openUrlInPreview<E>(input: {
readonly openPreview: OpenPreviewMutation<E>;
readonly profileId?: PreviewOpenInput["profileId"];
readonly background?: boolean;
}): Promise<AtomCommandResult<void, E | BrowserSettingsReadError>> {
}): Promise<AtomCommandResult<PreviewSessionSnapshot, E | BrowserSettingsReadError>> {
// Read before any await: a side chat pane that unmounts meanwhile drops its host mapping.
const threadRef = rightPanelHostRef(input.threadRef);
const defaults = await resolveBrowserDefaults().catch(
Expand Down Expand Up @@ -100,10 +100,11 @@ export async function openUrlInPreview<E>(input: {
) {
setActivePreviewTab(threadRef, previousActiveTabId);
}
return;
return snapshot;
}
applyPreviewServerSnapshot(threadRef, snapshot);
useRightPanelStore.getState().openBrowser(threadRef, snapshot.tabId);
return snapshot;
});
}

Expand All @@ -119,7 +120,7 @@ export async function openFileInPreview<AssetError, PreviewError>(input: {
readonly openPreview: OpenPreviewMutation<PreviewError>;
}): Promise<
AtomCommandResult<
void,
PreviewSessionSnapshot,
AssetError | PreviewError | BrowserPreviewUnavailableError | BrowserSettingsReadError
>
> {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/browser/useOpenLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function useOpenLink(threadRef: ScopedThreadRef | null | undefined): (
const result = await openUrlInPreview({ threadRef: targetThreadRef, url, openPreview });
if (isAtomCommandInterrupted(result)) return;
if (result._tag === "Success") {
recordVisitForThread(targetThreadRef, url);
recordVisitForThread(targetThreadRef, url, result.value.profileId);
return;
}
const failure = squashAtomCommandFailure(result);
Expand Down
158 changes: 119 additions & 39 deletions apps/web/src/browserHistoryStore.test.ts

Large diffs are not rendered by default.

27 changes: 20 additions & 7 deletions apps/web/src/browserHistoryStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import {
scopedThreadKey,
scopeProjectRef,
} from "@t3tools/client-runtime/environment";
import type {
EnvironmentId,
PreviewSessionSnapshot,
ScopedProjectRef,
ScopedThreadRef,
import {
INCOGNITO_BROWSER_PROFILE_ID,
type EnvironmentId,
type PreviewSessionSnapshot,
type ScopedProjectRef,
type ScopedThreadRef,
} from "@t3tools/contracts";
import { create } from "zustand";
import { createJSONStorage, persist } from "zustand/middleware";
Expand Down Expand Up @@ -398,9 +399,15 @@ function resolveThreadProjectKey(ref: ScopedThreadRef): string | undefined {
return projectKey;
}

export function recordVisitForThread(ref: ScopedThreadRef, url: string, at?: number): void {
export function recordVisitForThread(
ref: ScopedThreadRef,
url: string,
profileId?: string,
at?: number,
): void {
const threadKey = scopedThreadKey(ref);
const projectKey = resolveThreadProjectKey(ref);
if (profileId === INCOGNITO_BROWSER_PROFILE_ID) return;
const state = useBrowserHistoryStore.getState();
const visitAt = at ?? Date.now();
const connection = readPreparedConnection(ref.environmentId);
Expand Down Expand Up @@ -468,7 +475,13 @@ function recordPreviewTitles(
);
for (const session of sessions) {
const status = session.navStatus;
if (status._tag !== "Success" || !status.title || !include(session, status.url)) continue;
if (
session.profileId === INCOGNITO_BROWSER_PROFILE_ID ||
status._tag !== "Success" ||
!status.title ||
!include(session, status.url)
)
continue;
state.setTitleForUrl(projectKey, status.url, status.title, environmentHostname);
}
}
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/ChatMarkdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ function useChatMarkdownState({
);
}
return openUrlInPreview({ threadRef, url, openPreview }).then((result) => {
if (result._tag === "Success") recordVisitForThread(threadRef, url);
if (result._tag === "Success") recordVisitForThread(threadRef, url, result.value.profileId);
else if (!isAtomCommandInterrupted(result)) {
const error = squashAtomCommandFailure(result);
if (isBrowserSettingsReadError(error)) {
Expand Down
18 changes: 10 additions & 8 deletions apps/web/src/components/preview/PreviewView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,16 @@ export function PreviewView({

const navigateToResolvedUrl = async (resolvedUrl: string) => {
if (isServerTab && serverSurfaceRef.current) {
if (serverInputDisabled) return false;
if (serverInputDisabled) return null;
serverSurfaceRef.current.navigate(resolvedUrl);
rememberPreviewUrl(threadRef, resolvedUrl);
return true;
return { profileId: snapshot?.profileId };
}
if (runtimeTabId && previewBridge) {
await previewBridge.navigate(runtimeTabId, resolvedUrl);
rememberPreviewUrl(threadRef, resolvedUrl);
focusPreviewPage(runtimeTabId);
return true;
return { profileId: snapshot?.profileId };
}
const result = await openPreviewSession({ openPreview: open, threadRef, url: resolvedUrl });
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
Expand All @@ -272,14 +272,15 @@ export function PreviewView({
});
}
}
return result._tag === "Success";
return result._tag === "Success" ? result.value : null;
};

const handleSubmitUrl = async (next: string) => {
try {
const resolved = resolveAddressBarInput(next, resolveSearchUrlTemplate(getClientSettings()));
if (await navigateToResolvedUrl(resolved)) {
recordVisitForThread(threadRef, resolved);
const navigated = await navigateToResolvedUrl(resolved);
if (navigated) {
recordVisitForThread(threadRef, resolved, navigated.profileId);
}
} catch (error) {
toastManager.add({
Expand All @@ -300,8 +301,9 @@ export function PreviewView({
isServerTab || !previewBridge
? normalizePreviewUrl(next)
: resolveDiscoveredServerUrl(threadRef.environmentId, next);
if (await navigateToResolvedUrl(resolved)) {
recordVisitForThread(threadRef, next);
const navigated = await navigateToResolvedUrl(resolved);
if (navigated) {
recordVisitForThread(threadRef, next, navigated.profileId);
}
} catch (error) {
toastManager.add({
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/preview/openDiscoveredPort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export async function openDiscoveredPort<E>(input: {
url: resolvedUrl,
});
return mapAtomCommandResult(result, (snapshot) => {
recordVisitForThread(input.threadRef, input.port.url);
recordVisitForThread(input.threadRef, input.port.url, snapshot.profileId);
useRightPanelStore.getState().openBrowser(input.threadRef, snapshot.tabId);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function openTerminalLinkInPreview<E>(
input.fallbackToBrowser();
return;
}
recordVisitForThread(input.threadRef, input.url);
recordVisitForThread(input.threadRef, input.url, result.value.profileId);
applyPreviewServerSnapshot(input.threadRef, result.value);
useRightPanelStore.getState().openBrowser(input.threadRef, result.value.tabId);
}
Loading