-
Notifications
You must be signed in to change notification settings - Fork 872
feat(preview-server): buffer console logs until spinner is done #2725
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: canary
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 399acd0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
There was a problem hiding this 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
| log, | ||
| uncork: uncorkLog, | ||
| original: originalLog, | ||
| } = createLogBufferer(console.log); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/preview-server/src/actions/render-email-by-path.tsx, line 76:
<comment>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.</comment>
<file context>
@@ -52,12 +69,38 @@ export const renderEmailByPath = async (
+ log,
+ uncork: uncorkLog,
+ original: originalLog,
+ } = createLogBufferer(console.log);
+ console.log = log;
+ const {
</file context>
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 usingprocess.stdout.corkanduncork, butconsole.errandconsole.warnwrite toprocess.stderrwhich 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.
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.
Written for commit 399acd0. Summary will update automatically on new commits.