Remove debug console logs and duplicate tree rebuilds - #13
Conversation
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.
There was a problem hiding this comment.
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 frombuildFileTrie()andhandleNavOrRender(). - Added a microtask-based scheduler to coalesce same-tick
nav/renderevents into a singlehandleNavOrRender()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.
| if (e?.detail?.url) { | ||
| pendingDetail = { ...(pendingDetail || {}), ...e.detail }; | ||
| } else if (!pendingDetail) { | ||
| pendingDetail = e?.detail || {}; | ||
| } |
There was a problem hiding this comment.
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.
|
Hi @SaberZero — mind taking a look at this when you get a chance? Summary: Happy to adjust anything if you'd prefer a different approach. |
Summary
buildFileTrie()andhandleNavOrRender()inexplorer.inline.tshad roughly ten unconditionalconsole.log("[Explorer] ...")calls — no verbose/debug flag gates them, so every single page navigation dumps a full trace to the console in production:console.log("[Explorer] ...")tracing call. Kept the existingconsole.error/console.warncalls, since those report actual failure conditions (missing data, parse errors, fatal errors in the nav handler).handleNavOrRenderwas 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-ticknav/renderdispatches only trigger one rebuild, while still preserving the most recenturlfrom 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 typechecknpm run lintnpm run test(existingexplorer.test.tssuite passes)npm run build— verified the builtdist/index.jshas zeroconsole.logoccurrences and both"nav"/"render"listeners now point at the same coalescing functionAdded a changeset (
patchbump) describing the fix.