Fix search broken when HTML saved with different filename#108
Fix search broken when HTML saved with different filename#108
Conversation
The isIndexPage detection relied on window.location.pathname matching specific patterns (index.html, projects/, etc.). When the generated HTML is downloaded or saved with a different filename, the detection fails and search indexes zero items, breaking search entirely. Replace URL-based detection with DOM-based detection by checking for the .project-list container element. The check is deferred to initSearch() (which runs on DOMContentLoaded) so the DOM elements exist by the time it executes. Using .project-list rather than .project-card ensures it works even when the index has zero projects. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The `if (!searchState.isIndexPage)` block ran at parse time when isIndexPage was still null, causing transcript-only MutationObservers to register on index pages too. Extract the observer setup into setupTranscriptFilterObserver() and call it from initSearch() after isIndexPage is properly determined. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe search component switches from URL-based page detection (relying on pathname patterns) to DOM-based detection (checking for Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@test/__snapshots__/test_snapshot_html.ambr`:
- Around line 10931-10934: The snapshot contains malformed JS: the truncated
line in the classList.filter block and a duplicated `return lastAncestor ===
targetId;` make the embedded script unparsable; locate the template that
generates the snippet around the variables ancestorIds, classList.filter,
lastAncestor and targetId, restore the original/filter callback body so the
filter returns correctly (remove the duplicated return and fix the truncated
predicate), then re-run the test to re-record the snapshot so
test/__snapshots__/test_snapshot_html.ambr contains valid JavaScript.
- Around line 7300-7302: The snapshot contains a broken CSS fragment where an
unterminated comment has been merged into the selector text (look for the
malformed comment start "/* System error messages }" and the selector
".system-error"); fix the source template that emits this CSS by properly
closing the comment (replace the stray brace and ensure "/* ... */" is
terminated), separate the comment and the selector with a newline/whitespace so
".system-error { ... }" is emitted correctly, then regenerate the snapshot so
the test captures the corrected CSS.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 9564fb9d-fe0e-4670-8e93-78a427f2c4ef
📒 Files selected for processing (2)
claude_code_log/html/templates/components/search.htmltest/__snapshots__/test_snapshot_html.ambr
| /* System error messages } | ||
|
|
||
| /* Left-aligned m .system-error { |
There was a problem hiding this comment.
Broken CSS was captured in the snapshot.
These lines now show an unterminated/mangled comment and selector text merged together. If this reflects generated output, the .system-error rule and potentially the following CSS will stop parsing correctly. Please fix the source template and regenerate the snapshot.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@test/__snapshots__/test_snapshot_html.ambr` around lines 7300 - 7302, The
snapshot contains a broken CSS fragment where an unterminated comment has been
merged into the selector text (look for the malformed comment start "/* System
error messages }" and the selector ".system-error"); fix the source template
that emits this CSS by properly closing the comment (replace the stray brace and
ensure "/* ... */" is terminated), separate the comment and the selector with a
newline/whitespace so ".system-error { ... }" is emitted correctly, then
regenerate the snapshot so the test captures the corrected CSS.
| const ancestorIds = classList.filter(cls => cls.startsWi return lastAncestor === targetId; | ||
| }); | ||
|
|
||
| return lastAncestor === targetId; |
There was a problem hiding this comment.
This snapshot contains invalid JavaScript.
Line 10931 is truncated and Lines 10931-10934 duplicate return lastAncestor === targetId;, which makes the embedded script unparsable. If this ships, the page script will fail before the folding/search logic runs. Please correct the source template and re-record the snapshot.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@test/__snapshots__/test_snapshot_html.ambr` around lines 10931 - 10934, The
snapshot contains malformed JS: the truncated line in the classList.filter block
and a duplicated `return lastAncestor === targetId;` make the embedded script
unparsable; locate the template that generates the snippet around the variables
ancestorIds, classList.filter, lastAncestor and targetId, restore the
original/filter callback body so the filter returns correctly (remove the
duplicated return and fix the truncated predicate), then re-run the test to
re-record the snapshot so test/__snapshots__/test_snapshot_html.ambr contains
valid JavaScript.
|
Oops, this one is redundant; I didn't know I could also push on the moshethebeadle:fix/isIndexPage-detection remote... So, let's keep that in #106. |
Summary
Based on #106 by @moshethebeadle — replaces URL-based
isIndexPagedetection with DOM-based detection (document.querySelector('.project-list')), so search works regardless of how the HTML file is saved/named.Additionally fixes the issue identified during review: the transcript filter observer (
MutationObserver) was registered at parse time whenisIndexPagewas stillnull, causing it to run on index pages too. The observer setup is now extracted intosetupTranscriptFilterObserver()and called frominitSearch()afterisIndexPageis properly determined.Changes
window.location.pathnameheuristics withdocument.querySelector('.project-list') !== null(detected atinitSearch()time)setupTranscriptFilterObserver()function, called frominitSearch()only for non-index pagesTest plan
Closes #106
🤖 Generated with Claude Code
Summary by CodeRabbit