From 9cefcd0dd1a503c727c8bbb2deb1b631329b3a42 Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Fri, 20 Sep 2024 15:48:06 -0700 Subject: [PATCH] Revert "perf: eagerly compute explorer nodes to avoid re-render in memoized value" This reverts commit 16a9caa555a2d63b7ff8af0731fbfd3231d6225c. --- quartz/components/Explorer.tsx | 76 ++++++++++++++---------------- quartz/components/ExplorerNode.tsx | 13 +++-- 2 files changed, 45 insertions(+), 44 deletions(-) diff --git a/quartz/components/Explorer.tsx b/quartz/components/Explorer.tsx index df876ab..ec7c48e 100644 --- a/quartz/components/Explorer.tsx +++ b/quartz/components/Explorer.tsx @@ -7,7 +7,6 @@ import { ExplorerNode, FileNode, Options } from "./ExplorerNode" import { QuartzPluginData } from "../plugins/vfile" import { classNames } from "../util/lang" import { i18n } from "../i18n" -import { VNode } from "preact" // Options interface defined in `ExplorerNode` to avoid circular dependency const defaultOptions = { @@ -45,7 +44,6 @@ export default ((userOpts?: Partial) => { // memoized let fileTree: FileNode let jsonTree: string - let component: VNode let lastBuildId: string = "" function constructFileTree(allFiles: QuartzPluginData[]) { @@ -84,46 +82,44 @@ export default ((userOpts?: Partial) => { if (ctx.buildId !== lastBuildId) { lastBuildId = ctx.buildId constructFileTree(allFiles) - const tree = ExplorerNode({ node: fileTree, opts, fileData }) - component = ( -
- -
-
    - {tree} -
  • -
-
-
- ) } - return component + return ( +
+ +
+
    + +
  • +
+
+
+ ) } Explorer.css = explorerStyle diff --git a/quartz/components/ExplorerNode.tsx b/quartz/components/ExplorerNode.tsx index 3137a3f..e57d677 100644 --- a/quartz/components/ExplorerNode.tsx +++ b/quartz/components/ExplorerNode.tsx @@ -224,10 +224,15 @@ export function ExplorerNode({ node, opts, fullPath, fileData }: ExplorerNodePro class="content" data-folderul={folderPath} > - {node.children.map((childNode) => - // eagerly render children so we can memoize properly - ExplorerNode({ node: childNode, opts, fileData, fullPath: folderPath }), - )} + {node.children.map((childNode, i) => ( + + ))}