Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix: loading doc takes forever race condition (#890)

gbirmanc2fb9400a636
diff --git a/js/app/packages/block-pdf/component/Document.tsx b/js/app/packages/block-pdf/component/Document.tsx
index 4b319c3c09..a9e2fe828c 100644
--- a/js/app/packages/block-pdf/component/Document.tsx
+++ b/js/app/packages/block-pdf/component/Document.tsx
@@ -287,7 +287,12 @@ export function Document() {
const blockEl = blockElement();
if (!blockEl) return;
const viewer = getRootViewer();
- if (!documentSize()) return;
+ const size = documentSize();
+ if (!size) return;
+ // wait for valid dimensions
+ if (size.width === 0 || size.height === 0) {
+ return;
+ }
if (!mountRef || !viewer || viewer.isMounted) return;
viewer.mount(mountRef, blockEl);
});
diff --git a/js/app/packages/block-pdf/signal/location.ts b/js/app/packages/block-pdf/signal/location.ts
index 3aeee0e84f..1b8d58f41e 100644
--- a/js/app/packages/block-pdf/signal/location.ts
+++ b/js/app/packages/block-pdf/signal/location.ts
@@ -19,7 +19,7 @@ import {
import { buildSimpleEntityUrl } from '@core/util/url';
import { waitForSignal } from '@core/util/waitForSignal';
import { createCallback } from '@solid-primitives/rootless';
-import type { Accessor } from 'solid-js';
+import { type Accessor, createMemo } from 'solid-js';
import { z } from 'zod';
import { pdfViewLocation } from './document';
import {
@@ -143,14 +143,19 @@ export const pendingLocationParamsSignal =
export const searchLocationPendingSignal = createBlockSignal<boolean>(false);
+const useIsViewerReadyForScroll = () => {
+ const viewerHasVisiblePages = viewerHasVisiblePagesSignal.get;
+ return createMemo(() => viewerReadySignal() && viewerHasVisiblePages());
+};
+
createBlockEffect(() => {
const getViewer = useGetRootViewer();
const goToLinkLocationFromParams = useGoToLinkLocationFromParams();
+ const isViewerReady = useIsViewerReadyForScroll();
- const viewerReady = viewerReadySignal() && viewerHasVisiblePagesSignal.get();
const params = pendingLocationParamsSignal();
- if (viewerReady && params) {
+ if (isViewerReady() && params) {
// TODO: do we need to clear all overlays here
getViewer()?.clearAllOverlays();
@@ -724,15 +729,18 @@ function useGoToPdfLocation() {
const useGoToPreviousLocation = () => {
const getViewer = useGetRootViewer();
const getViewLocation = pdfViewLocation.get;
+ const isViewerReady = useIsViewerReadyForScroll();
return async () => {
const viewer = getViewer();
await waitForSignal(getViewLocation, (location) => !!location, 300).then(
(prevLocationHash) => {
- if (viewer && prevLocationHash) {
- viewer.goToLocationHash(prevLocationHash);
- }
+ waitForSignal(isViewerReady).then(() => {
+ if (viewer && prevLocationHash) {
+ viewer.goToLocationHash(prevLocationHash);
+ }
+ });
}
);
};