Skip to content

feat(preview-server): buffer console logs until spinner is done#2725

Merged
gabrielmfern merged 7 commits intocanaryfrom
feat/avoid-logging-over-spinner
Dec 12, 2025
Merged

feat(preview-server): buffer console logs until spinner is done#2725
gabrielmfern merged 7 commits intocanaryfrom
feat/avoid-logging-over-spinner

Conversation

@gabrielmfern
Copy link
Copy Markdown
Member

@gabrielmfern gabrielmfern commented Dec 10, 2025

I've always been annoyed at the fact that ora's spinners conflict with console.log statements during rendering, which sometimes, ends up eating away what you wanted to see in a console.log statement. To fix this, I've tried using process.stdout.cork and uncork, but console.err and console.warn write to process.stderr which is where ora also writes to, and corking will also buffer the spinner itself, which we don't want.

So, this just replaces the global console functions, storing the arguments to pass to the log function, and then once the spinner is done sends it all into the original function.

Before After
2025-12-12.18-06-45.mp4
2025-12-12.18-04-47.mp4

Summary by cubic

Prevents spinner output from overwriting console logs in the preview server by buffering logs during rendering and flushing them after the spinner stops.

  • New Features

    • Queue console.log/info/warn/error while the ora spinner runs, then flush and restore originals on success or error.
    • Send spinner output to stderr explicitly to avoid conflicts and ensure clean log output.
  • Bug Fixes

    • Handle nested buffer/flush calls to prevent race conditions and only flush once all buffers are released.

Written for commit 9520b08. Summary will update automatically on new commits.

@gabrielmfern gabrielmfern self-assigned this Dec 10, 2025
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Dec 10, 2025

🦋 Changeset detected

Latest commit: 9520b08

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

This PR includes changesets to release 2 packages
Name Type
@react-email/preview-server Patch
react-email Patch

Not sure what this means? Click here to learn what changesets are.

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

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Dec 10, 2025

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

Project Deployment Review Updated (UTC)
react-email Ready Ready Preview, Comment Dec 12, 2025 9:07pm
react-email-demo Ready Ready Preview, Comment Dec 12, 2025 9:07pm

@gabrielmfern gabrielmfern marked this pull request as ready for review December 10, 2025 19:28
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Dec 10, 2025

Open in StackBlitz

npm i https://pkg.pr.new/resend/react-email/@react-email/preview-server@2725

commit: 9520b08

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 2 files

Prompt for AI agents (all 1 issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="packages/preview-server/src/actions/render-email-by-path.tsx">

<violation number="1" location="packages/preview-server/src/actions/render-email-by-path.tsx:76">
P1: Race condition: concurrent calls to `renderEmailByPath` can corrupt global console methods. When a second call starts before the first finishes, it captures the buffered function as `original` instead of the real console method. Consider storing the original console methods once at module scope, or using a reference counter to only restore when all concurrent calls complete.</violation>
</file>

Reply to cubic to teach it or ask questions. Re-run a review with @cubic-dev-ai review this PR

@gabrielmfern gabrielmfern merged commit ff89ad8 into canary Dec 12, 2025
16 of 17 checks passed
@gabrielmfern gabrielmfern deleted the feat/avoid-logging-over-spinner branch December 12, 2025 21:08
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.

2 participants