Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(pdf): restore initial location after cancelling queued target (#7194)
gbirman68fd4098b331
diff --git a/apps/web/src/features/block-pdf/component/PdfDocument.test.tsx b/apps/web/src/features/block-pdf/component/PdfDocument.test.tsxindex b1134e5084..71befad4ac 100644--- a/apps/web/src/features/block-pdf/component/PdfDocument.test.tsx+++ b/apps/web/src/features/block-pdf/component/PdfDocument.test.tsx@@ -84,6 +84,10 @@ it.each([false, true])(test.setVisible(true);expect(state.navigate).not.toHaveBeenCalled();expect(state.clearOverlays).not.toHaveBeenCalled();+ expect(state.initial).toHaveBeenCalledExactlyOnceWith({+ pageNumber: '3',+ yPos: '0',+ });test.setTarget({ pdf_search_page: '8' });expect(state.navigate).toHaveBeenCalledExactlyOnceWith({@@ -102,12 +106,29 @@ it('preserves a newer imperative location when the route target clears', async (test.setReady(true);test.setVisible(true);expect(state.navigate).toHaveBeenCalledExactlyOnceWith(mention);+ expect(state.initial).not.toHaveBeenCalled();test.setVisible(false);test.setTarget({ pdf_search_page: '8' });test.setTarget(undefined);test.setVisible(true);expect(state.navigate).toHaveBeenCalledTimes(1);+ expect(state.initial).not.toHaveBeenCalled();+});++it('does not restore the initial location after a target has been applied', () => {+ const test = setup({ pdf_search_page: '7' }, true);+ test.setVisible(true);+ expect(state.navigate).toHaveBeenCalledExactlyOnceWith({+ pdf_search_page: '7',+ });+ test.setTarget(undefined);+ test.setVisible(false);+ test.setTarget({ pdf_search_page: '8' });+ test.setTarget(undefined);+ test.setVisible(true);+ expect(state.navigate).toHaveBeenCalledTimes(1);+ expect(state.initial).not.toHaveBeenCalled();});it('keeps legacy initial-location navigation when there is no route target', () => {diff --git a/apps/web/src/features/block-pdf/component/PdfDocument.tsx b/apps/web/src/features/block-pdf/component/PdfDocument.tsxindex 2fff23d053..02abe14a91 100644--- a/apps/web/src/features/block-pdf/component/PdfDocument.tsx+++ b/apps/web/src/features/block-pdf/component/PdfDocument.tsx@@ -113,7 +113,7 @@ function PdfDocumentBehavior(props: PdfDocumentProps) {createSignal<LocationBlockParams>();const goToInitialLocation = useGoToLinkLocation();const goToLocationFromParams = useGoToLinkLocationFromParams();- let imperativeNavigationQueued = false;+ let targetedNavigationStarted = false;let routeOwnsTarget = false;createEffect(() => {@@ -126,14 +126,12 @@ function PdfDocumentBehavior(props: PdfDocumentProps) {return;}routeOwnsTarget = true;- imperativeNavigationQueued = true;setPendingLocationParams({ ...target });});props.registerMethods?.({goToLocationFromParams: async (params) => {routeOwnsTarget = false;- imperativeNavigationQueued = true;setPendingLocationParams({ ...params });},});@@ -158,7 +156,12 @@ function PdfDocumentBehavior(props: PdfDocumentProps) {});createEffect(() => {- if (imperativeNavigationQueued || !pdfViewer.root.isReady()) return;+ if (+ targetedNavigationStarted ||+ pendingLocationParams() ||+ !pdfViewer.root.isReady()+ )+ return;void goToInitialLocation(pdf.locationParams());});@@ -171,6 +174,7 @@ function PdfDocumentBehavior(props: PdfDocumentProps) {) {return;}+ targetedNavigationStarted = true;setPendingLocationParams(undefined);pdfViewer.root.instance()?.clearAllOverlays();void goToLocationFromParams(params);diff --git a/docs/AGENT_GUIDE/surfaces.md b/docs/AGENT_GUIDE/surfaces.mdindex 80e14c9e8e..c5952e8988 100644--- a/docs/AGENT_GUIDE/surfaces.md+++ b/docs/AGENT_GUIDE/surfaces.md@@ -698,8 +698,9 @@ same snippet again to verify it re-targets. Repeat with Shift-click and Cmd/Ctrl(new split and new browser tab), and check Back/Forward restores the earlier target.Channel checks should include an older offscreen message, a reply, and then a rootmessage to ensure the previous thread target is cleared.-For a PDF that is still loading, clear its route target before pages become visible:-the old search hit must not apply afterward. A newer mention or preview target must+For a PDF that is still loading, clear its route target before pages become visible.+The old search hit must not apply afterward, and its normal initial position should+still restore if no target has been applied. A newer mention or preview target mustsurvive that cleanup and still open when the viewer is ready.Agent-session results use the robot icon and show a highlighted transcript snippet.