Skip to content

Fix search broken when HTML saved with different filename#108

Closed
cboos wants to merge 2 commits intomainfrom
fix/isIndexPage-detection
Closed

Fix search broken when HTML saved with different filename#108
cboos wants to merge 2 commits intomainfrom
fix/isIndexPage-detection

Conversation

@cboos
Copy link
Copy Markdown
Collaborator

@cboos cboos commented Apr 11, 2026

Summary

Based on #106 by @moshethebeadle — replaces URL-based isIndexPage detection 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 when isIndexPage was still null, causing it to run on index pages too. The observer setup is now extracted into setupTranscriptFilterObserver() and called from initSearch() after isIndexPage is properly determined.

Changes

  1. From Fix search broken when HTML saved with different filename #106: Replace window.location.pathname heuristics with document.querySelector('.project-list') !== null (detected at initSearch() time)
  2. New: Extract transcript filter observer into setupTranscriptFilterObserver() function, called from initSearch() only for non-index pages
  3. Updated snapshots

Test plan

  • Generate an index page and verify search works normally
  • Save the index page with a different filename and verify search still works
  • Verify search still works on transcript pages (non-index pages)
  • Verify filter observer doesn't register on index pages

Closes #106

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Improved search page detection mechanism to use DOM-based identification instead of URL pattern matching.
    • Enhanced transcript filter handling with better observer setup and index management for improved search accuracy on transcript pages.

Jake Toronto and others added 2 commits April 1, 2026 10:36
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>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 11, 2026

📝 Walkthrough

Walkthrough

The search component switches from URL-based page detection (relying on pathname patterns) to DOM-based detection (checking for .project-list element presence). The filter-change observer logic is refactored into an explicit setupTranscriptFilterObserver() function called only for transcript pages, replacing previous inline conditionals.

Changes

Cohort / File(s) Summary
Search Component Logic
claude_code_log/html/templates/components/search.html
Migrated searchState.isIndexPage initialization from URL pattern matching to runtime DOM detection. Added setupTranscriptFilterObserver() function to handle transcript-specific filter change observers, called conditionally during initSearch(). Removed top-level conditional depending on uninitialized searchState.isIndexPage.
Test Snapshots
test/__snapshots__/test_snapshot_html.ambr
Updated HTML snapshots to reflect refactored search initialization logic, including new setupTranscriptFilterObserver() function calls and adjusted CSS/script content for .system-error and filter-related code sections.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • feat(search): add search functionality #31: Directly modifies the same search component, including related changes to setupTranscriptFilterObserver() function and searchState.isIndexPage initialization behavior in initSearch().

Poem

🐰 We hopped through pathnames, got lost on the way,
Now we search the DOM—much clearer today!
No more broken links when the filename's new,
Just look at the content, and search knows what's true! 🔍✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: replacing URL-based page detection with DOM-based detection to fix search functionality when HTML is saved with different filenames.
Linked Issues check ✅ Passed The PR implements all requirements from issue #106: DOM-based detection via .project-list, deferred initialization in initSearch(), proper observer registration only on transcript pages, and snapshot updates.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the isIndexPage detection and organizing transcript-specific logic; no unrelated modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/isIndexPage-detection

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between f38e228 and be1e932.

📒 Files selected for processing (2)
  • claude_code_log/html/templates/components/search.html
  • test/__snapshots__/test_snapshot_html.ambr

Comment on lines +7300 to +7302
/* System error messages }

/* Left-aligned m .system-error {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

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.

Comment on lines +10931 to +10934
const ancestorIds = classList.filter(cls => cls.startsWi return lastAncestor === targetId;
});

return lastAncestor === targetId;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

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.

@cboos
Copy link
Copy Markdown
Collaborator Author

cboos commented Apr 11, 2026

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.

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.

1 participant