Skip to content

Remove debug console logs and duplicate tree rebuilds - #13

Open
suryaanshrai wants to merge 2 commits into
quartz-community:mainfrom
suryaanshrai:fix/remove-debug-console-logs
Open

Remove debug console logs and duplicate tree rebuilds#13
suryaanshrai wants to merge 2 commits into
quartz-community:mainfrom
suryaanshrai:fix/remove-debug-console-logs

Conversation

@suryaanshrai

Copy link
Copy Markdown

Summary

buildFileTrie() and handleNavOrRender() in explorer.inline.ts had roughly ten unconditional console.log("[Explorer] ...") calls — no verbose/debug flag gates them, so every single page navigation dumps a full trace to the console in production:

[Explorer] Fetching content index...
[Explorer] Entry count: 158
[Explorer] Trie root children: 9
[Explorer] Rendering 8 children
[Explorer] Render complete, final list length: 9
  • Removed every console.log("[Explorer] ...") tracing call. Kept the existing console.error/console.warn calls, since those report actual failure conditions (missing data, parse errors, fatal errors in the nav handler).
  • handleNavOrRender was bound directly to both the "nav" and "render" DOM events. When both fire for the same navigation (for example, a plugin that dispatches "render" right after updating the content index), the 100+ entry file tree gets rebuilt twice for one navigation. Added a small microtask-coalescing wrapper (scheduleNavOrRender) so same-tick nav/render dispatches only trigger one rebuild, while still preserving the most recent url from whichever event carried it.

No behavior change beyond removed logging and de-duplicated rebuilds — same trie building/rendering/collapse-state logic as before.

Test plan

  • npm run typecheck
  • npm run lint
  • npm run test (existing explorer.test.ts suite passes)
  • npm run build — verified the built dist/index.js has zero console.log occurrences and both "nav"/"render" listeners now point at the same coalescing function
  • Manually verified against a live Quartz site using this plugin: console is silent on both initial load and SPA navigation, and the explorer tree still renders and updates correctly on navigation

Added a changeset (patch bump) describing the fix.

buildFileTrie() and handleNavOrRender() had ~10 unconditional
console.log("[Explorer] ...") calls with no verbose/debug flag to gate
them, so every navigation flooded the console with tracing output
("Fetching content index...", "Entry count: N", "Trie root children: N",
"Rendering N children", "Render complete...", etc). Removed all of them,
keeping the console.error/console.warn calls that report real failures.

Also, handleNavOrRender was bound directly to both the "nav" and
"render" events. When both fire for the same navigation (e.g. a plugin
dispatching "render" after updating the content index), the file tree
was rebuilt twice. Added a microtask-coalescing wrapper so same-tick
nav/render dispatches trigger a single rebuild, while still keeping the
most recent url in the merged event detail.

No behavior change beyond removed logging and de-duplicated rebuilds.
Copilot AI lite review requested due to automatic review settings August 31, 2026 15:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes noisy unconditional debug logging from the Explorer inline script and adds same-tick event coalescing so the file tree isn’t rebuilt redundantly when both nav and render fire for a single navigation.

Changes:

  • Removed unconditional console.log("[Explorer] ...") traces from buildFileTrie() and handleNavOrRender().
  • Added a microtask-based scheduler to coalesce same-tick nav/render events into a single handleNavOrRender() run.
  • Added a patch changeset documenting the fix.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/components/scripts/explorer.inline.ts Removes debug logs and introduces a microtask coalescer for nav/render to avoid duplicate tree rebuilds.
.changeset/quiet-explorer-console.md Patch changeset describing the removed logs and event coalescing behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +406 to +410
if (e?.detail?.url) {
pendingDetail = { ...(pendingDetail || {}), ...e.detail };
} else if (!pendingDetail) {
pendingDetail = e?.detail || {};
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — fixed in ab8bf5f. The merge now happens unconditionally (spreading e.detail regardless of url's truthiness), and only falls back to the previous url when the new value is null/undefined, so an explicit "" is preserved.

Copilot review caught that gating the merge on e?.detail?.url being
truthy would silently discard a legitimate falsy url (e.g. "" for the
root page) and skip merging any other detail fields on that event.
Merge detail unconditionally and only fall back to the previous url
when the new one is null/undefined.
@suryaanshrai

Copy link
Copy Markdown
Author

Hi @SaberZero — mind taking a look at this when you get a chance?

Summary: explorer.inline.ts had ~10 unconditional console.log("[Explorer] ...") traces firing on every navigation (visible in prod consoles), and the handler was bound directly to both "nav" and "render", causing the file tree to rebuild twice for a single navigation when both events fire in the same tick. This PR removes the debug logs (keeping real console.error/console.warn paths) and adds a small microtask-based coalescer so same-tick nav/render dispatches only trigger one rebuild. No behavior change otherwise. Copilot's review caught an edge case in the coalescing logic (falsy "" url being dropped), which is fixed in a follow-up commit.

Happy to adjust anything if you'd prefer a different approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants