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(soup): fetching more data stuck in loop (#1536)

dev-rba81d2bf631d3
diff --git a/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx b/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx
index cc21b11f26..5cb3fec06d 100644
--- a/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/soup-view.tsx
@@ -17,7 +17,6 @@ import {
} from '@app/component/next-soup/soup-view/soup-view-context';
import { useSoupNavigationHotkeys } from './use-soup-navigation-hotkeys';
import { useSoupViewHotkeys } from './use-soup-view-hotkeys';
-import { useElementItemCount } from '@app/component/next-soup/use-element-item-count';
import { registerPreviewEntity } from '@app/signal/splitLayout';
import { useSplitLayout } from '@app/component/split-layout/layout';
import { fileTypeToResolvedBlockName } from '@core/constant/allBlocks';
@@ -78,8 +77,6 @@ import type { SystemSortOption } from '@app/component/next-soup/soup-view/sort-o
import { usePropertyEditorHotkeys } from '@app/component/property-edit-modal/hooks/usePropertyEditorHotkeys';
import type { SoupItemsQueryFilters } from '@queries/soup/items';
-const DEFAULT_ENTITY_HEIGHT = 40;
-
const useSoupNotificationInvalidators = () => {
const notificationSource = useGlobalNotificationSource();
const entityQueryClient = useQueryClient();
@@ -305,7 +302,7 @@ export const SoupViewList = (props: SoupViewListProps) => {
if (source.isFetchingNextPage() || !source.hasNextPage()) return;
source.fetchNextPage();
- });
+ }, 15);
const orchestrator = useGlobalBlockOrchestrator();
@@ -411,24 +408,6 @@ export const SoupViewList = (props: SoupViewListProps) => {
}
});
- const [listRef, setListRef] = createSignal<HTMLDivElement>();
-
- const viewportItemCount = useElementItemCount({
- element: listRef,
- itemHeight: DEFAULT_ENTITY_HEIGHT,
- });
-
- // Fetch more data if we filter out more items than the viewport can display
- // because it's possible that the match exists on the server
- createEffect(
- on([rows, viewportItemCount], ([rows, viewportItemCount]) => {
- if (rows.length >= viewportItemCount || source.isFetching()) return;
- debouncedFetchMore();
- })
- );
-
- onCleanup(() => debouncedFetchMore.clear());
-
const [localEntityListRef, setLocalEntityListRef] = createSignal<
HTMLDivElement | undefined
>();
@@ -527,7 +506,6 @@ export const SoupViewList = (props: SoupViewListProps) => {
data-soup-view-id={panel.handle.id + (previewPanel ? '-preview' : '')}
>
<div
- ref={setListRef}
class="@container/uList size-full unified-list-root flex flex-col"
classList={{
'border-r border-edge-muted': soup.previewEntity() !== undefined,
@@ -580,6 +558,10 @@ export const SoupViewList = (props: SoupViewListProps) => {
}
};
+ if (i() === Math.floor(rows().length * 0.8)) {
+ debouncedFetchMore();
+ }
+
return (
<EntityRow
entityId={row.original.id}
diff --git a/js/app/packages/app/component/next-soup/use-element-item-count.ts b/js/app/packages/app/component/next-soup/use-element-item-count.ts
deleted file mode 100644
index 2615a2daf1..0000000000
--- a/js/app/packages/app/component/next-soup/use-element-item-count.ts
+++ /dev/null
@@ -1,46 +0,0 @@
-import {
- createSignal,
- createEffect,
- onCleanup,
- type Accessor,
- createMemo,
-} from 'solid-js';
-
-const DEFAULT_HEIGHT = 600;
-
-interface Options {
- element: Accessor<HTMLElement | undefined>;
- itemHeight: number;
-}
-
-export const useElementItemCount = (options: Options) => {
- let containerSizeObserver: ResizeObserver | null = null;
-
- const [containerHeight, setContainerHeight] = createSignal(DEFAULT_HEIGHT);
-
- createEffect(() => {
- containerSizeObserver?.disconnect();
- const ref = options.element();
- if (!ref) return;
-
- // Initialize with current size of the container using this component
- const initial =
- ref.clientHeight || ref.getBoundingClientRect().height || DEFAULT_HEIGHT;
- setContainerHeight((prevHeight) => Math.max(prevHeight, initial));
-
- containerSizeObserver = new ResizeObserver((entries) => {
- const last = entries.pop();
- const nextHeight = last?.contentRect?.height ?? ref.clientHeight;
- if (Number.isFinite(nextHeight) && nextHeight > 0)
- setContainerHeight((prevHeight) => Math.max(prevHeight, nextHeight));
- });
- containerSizeObserver.observe(ref);
- onCleanup(() => containerSizeObserver?.disconnect());
- });
-
- const viewportItemCount = createMemo(() =>
- Math.max(1, Math.ceil(containerHeight() / options.itemHeight))
- );
-
- return viewportItemCount;
-};