Fix local filetree page tree open performance
This commit is contained in:
@@ -105,6 +105,35 @@ async function main() {
|
||||
const context = await browser.newContext();
|
||||
const page = await context.newPage();
|
||||
const browserDiagnostics = [];
|
||||
let holdStarredSidebarProjection = false;
|
||||
let releaseStarredSidebarProjection = null;
|
||||
let starredSidebarProjectionCompleted = false;
|
||||
let scopedFileProjectionStartedAt = 0;
|
||||
let scopedFileProjectionCompletedAt = 0;
|
||||
await page.route("**/api/tree/projections/sidebar**", async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
if (holdStarredSidebarProjection && url.searchParams.get("sourceKind") === "local_folder") {
|
||||
await new Promise((resolve) => {
|
||||
releaseStarredSidebarProjection = resolve;
|
||||
});
|
||||
starredSidebarProjectionCompleted = true;
|
||||
}
|
||||
await route.continue();
|
||||
});
|
||||
await page.route("**/api/tree/projections/file**", async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
if (
|
||||
holdStarredSidebarProjection
|
||||
&& url.pathname.endsWith("/api/tree/projections/file")
|
||||
&& url.searchParams.get("parentRelativePath") === "design"
|
||||
) {
|
||||
scopedFileProjectionStartedAt = scopedFileProjectionStartedAt || Date.now();
|
||||
await route.continue();
|
||||
scopedFileProjectionCompletedAt = Date.now();
|
||||
return;
|
||||
}
|
||||
await route.continue();
|
||||
});
|
||||
page.on("console", (message) => {
|
||||
browserDiagnostics.push(`console:${message.type()}:${message.text()}`);
|
||||
});
|
||||
@@ -226,11 +255,31 @@ async function main() {
|
||||
].join("");
|
||||
});
|
||||
|
||||
holdStarredSidebarProjection = true;
|
||||
const shortcutClickAt = Date.now();
|
||||
await cloudDesignShortcut.click({ timeout: UI_TIMEOUT_MS });
|
||||
await page.locator('#sidebar-file-tree-root[data-mnote-filetree-scope="design"] .tree-row[data-shell-mode="filetree"][data-local-relative-path="design/Brief.md"]').waitFor({
|
||||
state: "visible",
|
||||
timeout: 1_500,
|
||||
}).catch((error) => {
|
||||
if (releaseStarredSidebarProjection) releaseStarredSidebarProjection();
|
||||
throw new Error(`星标文件夹 scoped FileTree 应先于页面树 projection 可交互: elapsed=${Date.now() - shortcutClickAt}ms fileStarted=${scopedFileProjectionStartedAt} fileDone=${scopedFileProjectionCompletedAt} sidebarDone=${starredSidebarProjectionCompleted}; ${error.message}`);
|
||||
});
|
||||
assert.equal(starredSidebarProjectionCompleted, false, "scoped FileTree 可见时,延迟中的 page tree projection 不应已经完成");
|
||||
assert(scopedFileProjectionStartedAt > 0, "点击星标文件夹后应立即启动 scoped file projection");
|
||||
assert(scopedFileProjectionCompletedAt > 0, "点击星标文件夹后 scoped file projection 应先完成");
|
||||
if (releaseStarredSidebarProjection) releaseStarredSidebarProjection();
|
||||
await page.locator('#sidebar-file-tree-root[data-mnote-filetree-scope="design"]').waitFor({
|
||||
state: "visible",
|
||||
timeout: UI_TIMEOUT_MS,
|
||||
});
|
||||
holdStarredSidebarProjection = false;
|
||||
await page.waitForFunction(() => {
|
||||
const root = document.querySelector("#sidebar-tree-root");
|
||||
if (!(root instanceof HTMLElement)) return false;
|
||||
const stale = root.querySelectorAll('.tree-row[data-shell-mode="page"][data-node-id="stale-my-space-page"]').length;
|
||||
return stale === 0 && /Brief/.test(root.innerText || "");
|
||||
}, { timeout: UI_TIMEOUT_MS });
|
||||
const scopedExplorerUrl = new URL(page.url());
|
||||
assert.equal(scopedExplorerUrl.searchParams.get("sourceKind"), "local_folder", "点击星标文件夹后应切到本地文件夹 source");
|
||||
assert.equal(scopedExplorerUrl.searchParams.get("rootUri"), rootUri, "点击星标文件夹后 URL 应保留显式 rootUri");
|
||||
|
||||
Reference in New Issue
Block a user