Skip to content

fix: refrain from using prismjs for syntax highlighting on older browsers - #2480

Merged
ranst91 merged 5 commits into
mainfrom
fix/old-browser-support-code-block
Sep 24, 2025
Merged

ranst91 merged 5 commits into
mainfrom
fix/old-browser-support-code-block

Conversation

@ranst91

@ranst91 ranst91 commented Sep 23, 2025 •

Copy link
Copy Markdown
Contributor

Older browsers might not support "lookback assertions", which are using in the code block in prismjs.
if these are not supported, we will default to an engine that does not use this assertion

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability of code block syntax highlighting by automatically choosing a compatible highlighter at runtime, preventing breakage on older browsers.
  • Refactor

    • Updated internal detection logic to select the best highlighting method based on environment capabilities; no changes to component APIs or visible behavior.

@vercel

vercel Bot commented Sep 23, 2025 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
docs Ready Ready Preview Comment Sep 24, 2025 8:09am
examples-coagents-ai-travel-app Canceled Canceled Sep 24, 2025 8:09am
examples-coagents-research-canvas-ui Ready Ready Preview Comment Sep 24, 2025 8:09am
1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
examples-coagents-ai-researcher-ui Ignored Ignored Sep 24, 2025 8:09am

@coderabbitai

coderabbitai Bot commented Sep 23, 2025 •

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@ranst91 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 44 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between fc6fa47 and a421148.

📒 Files selected for processing (1)
  • CopilotKit/packages/react-ui/src/components/chat/CodeBlock.tsx (2 hunks)

Walkthrough

Replaces a static Prism import in CodeBlock.tsx with a runtime selection that picks Prism if RegExp lookbehind is supported, otherwise falls back to Light. No public API, rendering behavior, or exported signatures were changed.

Changes

Cohort / File(s) Summary
Dynamic syntax highlighter selection
CopilotKit/packages/react-ui/src/components/chat/CodeBlock.tsx
Replace fixed Prism import with a useMemo runtime choice between Prism and Light by testing RegExp lookbehind support; rendering path and public API unchanged.
Changeset
CopilotKit/.changeset/loud-ways-smell.md
Add patch-level changeset documenting the fix to avoid using Prism on older browsers.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as CodeBlock (render)
  participant M as useMemo
  participant E as Env (RegExp)
  participant P as Prism Highlighter
  participant L as Light Highlighter

  U->>M: compute SyntaxHighlighter
  M->>E: test RegExp lookbehind support
  alt lookbehind supported
    M-->>U: select Prism
    U->>P: render(code, language)
  else not supported
    M-->>U: select Light
    U->>L: render(code, language)
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • suhasdeshpande
  • ataibarkai
  • tylerslaton
  • mme

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately summarizes the primary change: avoiding PrismJS for syntax highlighting on older browsers. It directly reflects the implemented behavior (selecting Prism or Light based on lookbehind support) and is clear and specific for reviewers. The phrasing is concise and focused on the main intent.

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.

@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: 3

🧹 Nitpick comments (1)
CopilotKit/packages/react-ui/src/components/chat/CodeBlock.tsx (1)

2-2: Avoid eagerly bundling both Prism and Light; code‑split the fallback.

Importing both engines increases bundle size even when one is unused. Prefer lazy loading the chosen engine.

Example (non-blocking):

// at top-level
const PrismHighlighter = React.lazy(() =>
  import("react-syntax-highlighter").then((m) => ({ default: m.Prism })),
);
const LightHighlighter = React.lazy(() =>
  import("react-syntax-highlighter").then((m) => ({ default: m.Light })),
);

// then render with <Suspense> and pick one after mount similar to your detection.
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 461517d and 16e5e3f.

📒 Files selected for processing (1)
  • CopilotKit/packages/react-ui/src/components/chat/CodeBlock.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
CopilotKit/packages/react-ui/**

📄 CodeRabbit inference engine (.cursor/rules/copilotkit-architecture.mdc)

UI components for copilot interfaces should be placed in CopilotKit/packages/react-ui/

Files:

  • CopilotKit/packages/react-ui/src/components/chat/CodeBlock.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/frontend-development.mdc)

Use TypeScript for better type safety

Files:

  • CopilotKit/packages/react-ui/src/components/chat/CodeBlock.tsx
{**/*.{ts,tsx},CopilotKit/utilities/tailwind-config/**}

📄 CodeRabbit inference engine (.cursor/rules/frontend-development.mdc)

Maintain consistent styling with Tailwind CSS

Files:

  • CopilotKit/packages/react-ui/src/components/chat/CodeBlock.tsx
{CopilotKit/packages/react-ui/**/*.{ts,tsx},examples/**/ui/**/*.{ts,tsx}}

📄 CodeRabbit inference engine (.cursor/rules/frontend-development.mdc)

{CopilotKit/packages/react-ui/**/*.{ts,tsx},examples/**/ui/**/*.{ts,tsx}}: Implement responsive design
Provide clear user feedback

Files:

  • CopilotKit/packages/react-ui/src/components/chat/CodeBlock.tsx
CopilotKit/packages/react-ui/**/*

📄 CodeRabbit inference engine (.cursor/rules/quick-reference.mdc)

Add [react-ui/] for pre-built components when building a simple Copilot or customizing UI components

Files:

  • CopilotKit/packages/react-ui/src/components/chat/CodeBlock.tsx
🧠 Learnings (1)
📚 Learning: 2025-07-20T15:40:00.391Z
Learnt from: CR
PR: CopilotKit/CopilotKit#0
File: .cursor/rules/suggestions-development.mdc:0-0
Timestamp: 2025-07-20T15:40:00.391Z
Learning: Applies to packages/react-ui/src/hooks/use-copilot-chat-suggestions.tsx : Check useEffect dependencies and ensure they're properly memoized to avoid infinite re-renders

Applied to files:

  • CopilotKit/packages/react-ui/src/components/chat/CodeBlock.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: Build Images (next-openai, next-openai)
  • GitHub Check: Build Images (coagents-qa-native, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-qa-native, ui)
  • GitHub Check: Build Images (coagents-qa-text, ui)
  • GitHub Check: Build Images (coagents-qa-text, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-routing, ui)
  • GitHub Check: Build Images (coagents-research-canvas, ui)
  • GitHub Check: Build Images (coagents-routing, agent, python, local-deps)
  • GitHub Check: Build Images (coagents-research-canvas, agent, python, local-deps)
  • GitHub Check: E2E Tests
  • GitHub Check: Test (20.x)
  • GitHub Check: Test (18.x)

@github-actions

github-actions Bot commented Sep 24, 2025 •

Copy link
Copy Markdown
Contributor

Test Results

Status: ✅ Passed (View Run)

Commit: dce6525

Duration: 249.3s

Total Tests: 37

Pass Rate: 100.0%

Failed Tests: 0

🔍 Detailed Results

coagents-research-canvas

CoAgents Research Canvas (UI) - Local Depenencies

Model Browser Status Video
OpenAI chromium ✅ PASSED -
Anthropic chromium ✅ PASSED -
CrewAI chromium ✅ PASSED -

coagents-qa-native

CoAgents QA Native (UI) - Local

Model Browser Status Video
OpenAI chromium ✅ PASSED -
Anthropic chromium ✅ PASSED -

coagents-qa-text

CoAgents QA Text (UI) - Local

Model Browser Status Video
OpenAI chromium ✅ PASSED -
Anthropic chromium ✅ PASSED -
OpenAI (LGC Python) chromium ✅ PASSED -
Anthropic (LGC Python) chromium ✅ PASSED -
OpenAI (LGC JS) chromium ✅ PASSED -
Anthropic (LGC JS) chromium ✅ PASSED -

coagents-routing

CoAgents Routing (UI) - Local

Model Browser Status Video
OpenAI chromium ✅ PASSED -
Anthropic chromium ✅ PASSED -

next-openai

Next OpenAI - Self Hosted

Model Browser Status Video
OpenAI chromium ✅ PASSED -
Anthropic chromium ✅ PASSED -
LangChain (OpenAI) chromium ✅ PASSED -
Groq chromium ✅ PASSED -

@changesets-bot-copilotkit

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a421148

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@copilotkit/react-ui Patch
@copilotkit/react-core Patch
@copilotkit/react-textarea Patch
@copilotkit/runtime-client-gql Patch
@copilotkit/runtime Patch
@copilotkit/sdk-js Patch
@copilotkit/shared Patch

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

Copy link
Copy Markdown
Contributor

Previews

Commit SHA: 18cf2d7

Name Preview
coagents-research-canvas Preview • Preview with LGC Python • Preview with LGC JS
coagents-qa-text Preview • Preview with LGC Python • Preview with LGC JS
coagents-routing Preview • Preview with LGC Python • Preview with LGC JS
coagents-qa-native Preview • Preview with LGC Python • Preview with LGC JS
next-openai Preview

This branch was successfully deployed

3 active deployments
Preview – examples-coagents-research-canvas-ui — a421148b Deployed Sep 24, 2025 by vercel[bot]
Preview – examples-coagents-ai-travel-app — a421148b Deployed Sep 24, 2025 by vercel[bot]
Preview – docs — a421148b Deployed Sep 24, 2025 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant