Skip to content

fix(web): lazy-load search code preview#1433

Open
brendan-kellam wants to merge 2 commits into
mainfrom
brendan/fix-lazy-code-preview
Open

fix(web): lazy-load search code preview#1433
brendan-kellam wants to merge 2 commits into
mainfrom
brendan/fix-lazy-code-preview

Conversation

@brendan-kellam

@brendan-kellam brendan-kellam commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Summary

  • lazy-load CodePreviewPanel so CodeMirror is excluded from the initial search-page module graph
  • pre-warm common language parser chunks when the search results page mounts
  • remove an unused Session import from the touched component

Validation

  • yarn workspace @sourcebot/web eslint src/app/\\(app\\)/search/components/searchResultsPage.tsx src/lib/codeHighlight.ts
  • yarn workspace @sourcebot/web tsc --noEmit (blocked by pre-existing type errors in unrelated test fixtures)
  • yarn workspace @sourcebot/web build (Turbopack compilation stalled without output and was stopped)

Note

Low Risk
Client-only bundle-splitting and background parser prefetch on the search UI; no auth, API, or data-path changes.

Overview
Improves initial search page load by deferring heavy editor/highlighting code until it is needed, while still warming likely language parsers in the background.

CodePreviewPanel is now loaded with next/dynamic (ssr: false) instead of a static import, so CodeMirror and the preview panel stay out of the first paint bundle until a user opens a file preview. On mount, the page pre-fetches Lezer parsers for a fixed list of common languages (TypeScript, JavaScript, Python, Go, Rust, Java, C++, C#, JSON) via getCodeParserByLanguageName, so opening a preview is less likely to wait on parser chunks. An unused Session import was removed from the search results page. CHANGELOG documents the performance fix (#1433).

Reviewed by Cursor Bugbot for commit 4a5c1a7. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • Bug Fixes
    • Improved initial search page loading by loading code previews on demand.
    • Preloaded common programming-language parsers to make code previews appear faster.
  • Documentation
    • Added an unreleased changelog entry documenting the search performance improvements.

@github-actions

This comment has been minimized.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Search results now client-load the code preview panel and pre-initialize parsers for common languages when the page mounts. The changelog records this behavior.

Changes

Search code preview loading

Layer / File(s) Summary
Code preview and parser initialization
packages/web/src/app/(app)/search/components/searchResultsPage.tsx, CHANGELOG.md
CodePreviewPanel is dynamically imported without SSR, common language parsers are loaded on mount with Promise.allSettled, and the changelog is updated.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 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 clearly describes the main change: lazy-loading the search code preview.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch brendan/fix-lazy-code-preview

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/web/src/app/`(app)/search/components/searchResultsPage.tsx:
- Line 18: Replace the top-level getCodeParserByLanguageName import with a
dynamic import inside the search page’s pre-warming effect, and invoke the
loaded helper there so `@/lib/codeHighlight` and its CodeMirror parser
dependencies are fetched only when the page mounts.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fbb5bd41-4e15-4519-b131-35b82975b9b5

📥 Commits

Reviewing files that changed from the base of the PR and between d9d252b and 4a5c1a7.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • packages/web/src/app/(app)/search/components/searchResultsPage.tsx

import useCaptureEvent from "@/hooks/useCaptureEvent";
import { useNonEmptyQueryParam } from "@/hooks/useNonEmptyQueryParam";
import { useSearchHistory } from "@/hooks/useSearchHistory";
import { getCodeParserByLanguageName } from "@/lib/codeHighlight";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n## searchResultsPage.tsx\n'
sed -n '1,220p' 'packages/web/src/app/(app)/search/components/searchResultsPage.tsx'

printf '\n## codeHighlight.ts\n'
sed -n '1,260p' 'packages/web/src/lib/codeHighlight.ts'

printf '\n## usages of getCodeParserByLanguageName\n'
rg -n "getCodeParserByLanguageName|codeHighlight" packages/web/src -g '!**/*.map'

Repository: sourcebot-dev/sourcebot

Length of output: 13635


Dynamically import @/lib/codeHighlight here

This client page statically pulls the CodeMirror parser helpers into the initial chunk. Load them inside the pre-warming effect instead so the parser bundle is fetched only when the search page mounts.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/web/src/app/`(app)/search/components/searchResultsPage.tsx at line
18, Replace the top-level getCodeParserByLanguageName import with a dynamic
import inside the search page’s pre-warming effect, and invoke the loaded helper
there so `@/lib/codeHighlight` and its CodeMirror parser dependencies are fetched
only when the page mounts.

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4a5c1a7. Configure here.

const CodePreviewPanel = dynamic(
() => import("./codePreviewPanel").then(module => ({ default: module.CodePreviewPanel })),
{ ssr: false },
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Blank preview while chunk loads

Medium Severity

When the preview panel is opened, the resizable panel mounts immediately. However, because CodePreviewPanel is dynamically loaded with ssr: false and lacks a loading fallback, users see an empty panel until the component's chunk finishes loading, which is noticeable on slower networks.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4a5c1a7. Configure here.

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