Skip to content

perf: lazy-load Algolia DocSearch to reduce initial bundle size - #5677

Closed
lb1192176991-lab wants to merge 1 commit into
asyncapi:masterfrom
lb1192176991-lab:fix/lazy-load-docsearch
Closed

perf: lazy-load Algolia DocSearch to reduce initial bundle size#5677
lb1192176991-lab wants to merge 1 commit into
asyncapi:masterfrom
lb1192176991-lab:fix/lazy-load-docsearch

Conversation

@lb1192176991-lab

@lb1192176991-lab lb1192176991-lab commented Jul 31, 2026

Copy link
Copy Markdown

What

This PR replaces the static import of DocSearchModal from @docsearch/react with a next/dynamic lazy import, and removes the render-blocking CSS @import of @docsearch/css from globals.css.

Changes:

  • components/AlgoliaSearch.tsx: Use next/dynamic to code-split DocSearchModal — it is only loaded when a user opens search
  • styles/globals.css: Remove the synchronous @import — the CSS is loaded as a side-effect of the dynamic import

Why

Every page on the AsyncAPI website was downloading and parsing the ~200 KB @docsearch/react bundle upfront, even though the search modal is only displayed when a user explicitly opens it. The render-blocking CSS @import was also delaying the browser first paint.

This negatively impacts Core Web Vitals:

  • FCP / LCP: render-blocking CSS delayed first paint
  • TBT / TTI: unnecessary JavaScript parsing on every page load

With this change, the DocSearch assets are only loaded on demand when a user triggers search (Ctrl+K or / key), reducing initial bundle size and eliminating the render-blocking CSS.

Testing

  • Verified that next/dynamic with ssr: false correctly lazy-loads DocSearchModal only when rendered
  • The CSS from @docsearch/css is bundled with the dynamic chunk and loaded on demand
  • Search functionality (Ctrl+K, / key, search button click) continues to work as before
  • No visual regressions — the DocSearch modal renders identically

Summary by CodeRabbit

  • Bug Fixes
    • Improved search modal loading for more reliable page rendering.
    • Removed the external stylesheet dependency for search styling.

Replace static import of DocSearchModal with next/dynamic to code-split
the ~200 KB @docsearch/react dependency. Remove the render-blocking CSS
@import from globals.css — the CSS is loaded as a side-effect of the
dynamic import only when the user opens search.

Fixes asyncapi#5673
@netlify

netlify Bot commented Jul 31, 2026

Copy link
Copy Markdown

Deploy Preview for asyncapi-website ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 80d319e
🔍 Latest deploy log https://app.netlify.com/projects/asyncapi-website/deploys/6a6cfa867d5b7700087a7899
😎 Deploy Preview https://deploy-preview-5677--asyncapi-website.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions 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.

Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai

coderabbitai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

DocSearchModal now loads through a client-only dynamic import. The global DocSearch CSS CDN import is removed.

Changes

DocSearch loading

Layer / File(s) Summary
Client-only DocSearch integration
components/AlgoliaSearch.tsx, styles/globals.css
DocSearchModal loads dynamically from @docsearch/react with server-side rendering disabled. The global DocSearch CSS CDN import is removed.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

  • asyncapi/website#5673: Directly overlaps with the dynamic DocSearchModal import and removal of the global DocSearch CSS import.

Suggested reviewers: princerajpoot20, akshatnema

🚥 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 and concisely describes the main change: lazy-loading Algolia DocSearch to reduce the initial bundle size.
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 unit tests (beta)
  • Create PR with unit tests

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 `@components/AlgoliaSearch.tsx`:
- Around line 11-14: Run the repository formatter on the DocSearchModal dynamic
import declaration in AlgoliaSearch.tsx and apply the resulting Prettier
formatting without changing its behavior.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 39b76970-d5ae-4b7b-9dad-996151e5a29f

📥 Commits

Reviewing files that changed from the base of the PR and between b9ccd73 and 80d319e.

📒 Files selected for processing (2)
  • components/AlgoliaSearch.tsx
  • styles/globals.css
💤 Files with no reviewable changes (1)
  • styles/globals.css

Comment on lines +11 to +14
const DocSearchModal = dynamic(
() => import('@docsearch/react').then((mod) => ({ default: mod.DocSearchModal })),
{ ssr: false }
);

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Fix the Prettier errors before merge.

ESLint reports prettier/prettier errors on Lines 11-14. Run the repository formatter.

Proposed formatting fix
-const DocSearchModal = dynamic(
-  () => import('`@docsearch/react`').then((mod) => ({ default: mod.DocSearchModal })),
-  { ssr: false }
-);
+const DocSearchModal = dynamic(() => import('`@docsearch/react`').then((mod) => ({ default: mod.DocSearchModal })), {
+  ssr: false
+});
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const DocSearchModal = dynamic(
() => import('@docsearch/react').then((mod) => ({ default: mod.DocSearchModal })),
{ ssr: false }
);
const DocSearchModal = dynamic(() => import('`@docsearch/react`').then((mod) => ({ default: mod.DocSearchModal })), {
ssr: false
});
🧰 Tools
🪛 ESLint

[error] 11-12: Replace ⏎··()·=>·import('@docsearch/react').then((mod)·=>·({·default:·mod.DocSearchModal·})), with ()·=>·import('@docsearch/react').then((mod)·=>·({·default:·mod.DocSearchModal·})),·{

(prettier/prettier)


[error] 13-14: Replace ·{·ssr:·false·}⏎ with ·ssr:·false⏎}

(prettier/prettier)

🤖 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 `@components/AlgoliaSearch.tsx` around lines 11 - 14, Run the repository
formatter on the DocSearchModal dynamic import declaration in AlgoliaSearch.tsx
and apply the resulting Prettier formatting without changing its behavior.

Source: Linters/SAST tools

@asyncapi-bot

Copy link
Copy Markdown
Contributor

⚡️ Lighthouse report for the changes in this PR:

Category Score
🔴 Performance 49
🟢 Accessibility 98
🟢 Best practices 92
🟢 SEO 100
🔴 PWA 33

Lighthouse ran on https://deploy-preview-5677--asyncapi-website.netlify.app/

@princerajpoot20

Copy link
Copy Markdown
Member

@lb1192176991-lab As mentioned in the issue, this is part of the Microgrant/Bounty Program and has already been assigned.

Please refrain from working on it. Refer to the Microgrant Program rules here: https://github.com/asyncapi/community/blob/master/docs/010-contribution-guidelines/microgrant-program.md

@github-project-automation github-project-automation Bot moved this from To Be Triaged to Done in Website - Kanban Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants