Skip to content

Conversation

@lerouxb
Copy link
Contributor

@lerouxb lerouxb commented Oct 9, 2025

We're also doing something similar for cli-repl.

At some point babel switched from chalk to picocolors: babel/babel#16359
where color detection seems to be broken: alexeyraspopov/picocolors#85
and there are some pretty complicated attempts at trying to fix it: alexeyraspopov/picocolors#87
with relatively frequent bugs and complaints: alexeyraspopov/picocolors#41

This results in syntax errors in the embedded shell in Compass on Windows having ansi escape sequences for syntax hilighting that's not supported. The workaround here is to just strip any ansi sequences from the message and stack.

I tested this manually on windows using browser-repl's sync-to-compass.js script and it seems to work.

@lerouxb lerouxb requested a review from a team as a code owner October 9, 2025 12:49
Copilot AI review requested due to automatic review settings October 9, 2025 12:49
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses a visual issue in the browser REPL where ANSI escape sequences appear in syntax error messages in Compass on Windows. The fix strips ANSI codes from syntax error messages and stack traces to improve readability.

  • Adds strip-ansi dependency to remove ANSI escape sequences from syntax errors
  • Modifies error rendering to conditionally strip ANSI codes only for SyntaxError types
  • Includes comprehensive tests for both collapsed and expanded error display modes

Reviewed Changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.

File Description
packages/browser-repl/src/components/types/error-output.tsx Imports strip-ansi and applies it conditionally to SyntaxError messages and stack traces
packages/browser-repl/src/components/types/error-output.spec.tsx Adds tests verifying ANSI codes are stripped from syntax errors in both collapsed and expanded views
packages/browser-repl/package.json Adds strip-ansi dependency for removing ANSI escape sequences

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

"react-refresh": "^0.14.0",
"rimraf": "^3.0.2",
"stream-browserify": "^3.0.0",
"strip-ansi": "^6.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

latest for this is 7.1.2, any reason for earlier version?

Copy link
Contributor

Choose a reason for hiding this comment

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

ah, I see, we already use this package

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same we use in the rest of the project

Copy link
Contributor

@gagik gagik Oct 9, 2025

Choose a reason for hiding this comment

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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice :) I think it's fine to just leave a mental note to prefer that in the future, keeping things working as they do for the CLI seems like a perfectly fine approach for now

@addaleax addaleax changed the title fix: strip ansi codes from syntax errors in browser-repl COMPASS-9921 fix(browser-repl): strip ansi codes from syntax errors COMPASS-9921 Oct 9, 2025
@lerouxb lerouxb merged commit eb7bcd6 into main Oct 10, 2025
149 of 157 checks passed
@lerouxb lerouxb deleted the strip-ansi-codes-from-syntax-errors branch October 10, 2025 15:05
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.

4 participants