Skip to content

Commit f29359b

Browse files
committed
refactor: ! Detect when QueryRenderChild objects become newly visible
For now, it just writes a log message. Eventually it will render, if necessary.
1 parent 78a06ae commit f29359b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/Renderer/QueryRenderer.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ class QueryRenderChild extends MarkdownRenderChild {
9191

9292
private renderEventRef: EventRef | undefined;
9393
private queryReloadTimeout: NodeJS.Timeout | undefined;
94+
private observer: IntersectionObserver | null = null;
9495

9596
private readonly queryResultsRenderer: QueryResultsRenderer;
9697

@@ -162,6 +163,28 @@ class QueryRenderChild extends MarkdownRenderChild {
162163
this.handleMetadataOrFilePathChange(tFile.path, fileCache);
163164
}),
164165
);
166+
167+
this.setupVisibilityObserver();
168+
}
169+
170+
private setupVisibilityObserver() {
171+
if (this.observer) {
172+
return;
173+
}
174+
175+
this.observer = new IntersectionObserver((entries) => {
176+
for (const entry of entries) {
177+
const visible = entry.isIntersecting && this.containerEl.isShown();
178+
if (visible) {
179+
this.queryResultsRenderer.query.warn(`[render][observer] Became visible, with this source:
180+
---
181+
${this.queryResultsRenderer.query.source}
182+
---`);
183+
}
184+
}
185+
});
186+
187+
this.observer.observe(this.containerEl);
165188
}
166189

167190
private handleMetadataOrFilePathChange(filePath: string, fileCache: CachedMetadata | null) {
@@ -189,6 +212,9 @@ class QueryRenderChild extends MarkdownRenderChild {
189212
if (this.queryReloadTimeout !== undefined) {
190213
clearTimeout(this.queryReloadTimeout);
191214
}
215+
216+
this.observer?.disconnect();
217+
this.observer = null;
192218
}
193219

194220
/**

0 commit comments

Comments
 (0)