Skip to content

fix(website, core):Fix race condition in web preview rendering.#291

Merged
TeseySTD merged 2 commits intoRazorConsole:mainfrom
TeseySTD:fix/website-render
Jan 29, 2026
Merged

fix(website, core):Fix race condition in web preview rendering.#291
TeseySTD merged 2 commits intoRazorConsole:mainfrom
TeseySTD:fix/website-render

Conversation

@TeseySTD
Copy link
Member

Solves #290

This PR fixes an issue where state changes (such as button clicks) were not immediately reflected in the website preview console, requiring a second interaction to update the display.

Problem:
The RazorConsoleRenderer was subscribing directly to the ConsoleRenderer. This caused a race condition where the renderer attempted to read the output buffer (StringWriter) before the ConsoleLiveDisplayContext and LiveDisplayCanvas had finished writing the new frame to it.

Solution:

  • Modified LiveDisplayCanvas to expose a Refreshed event that fires immediately after renderable is written to the console.
  • Updated RazorConsoleRenderer to subscribe to _canvas.Refreshed instead of the raw ConsoleRenderer snapshot. This ensures the buffer is captured only after the underlying ANSI output has been fully written.
  • Adjusted the initialization order in RazorConsoleRenderer to correctly capture the initial component render.

Changes:

  • LiveDisplayCanvas.cs: Added Refreshed event invocation in UpdateTarget and Refresh.
  • RazorConsoleRenderer.cs: Removed IObserver implementation and switched to event-based flushing via LiveDisplayCanvas.

@github-actions
Copy link

🚀 Preview Deployment

A preview build has been generated for this PR from CI run #21436818516!

Download the artifact:
website-preview-291-c6ab1f809667631b68deb6b5a2d9b04c6b1b9a74

To view the preview locally:

  1. Download the artifact from the CI workflow run
  2. Extract the ZIP file
  3. Serve the files with a local web server
    (e.g., npx serve dist)

🌐 Live Preview URL: https://57e3f42a.razorconsole.pages.dev

The live preview will be automatically updated when you push new
commits to this PR.

@TeseySTD TeseySTD merged commit 9de8ee7 into RazorConsole:main Jan 29, 2026
7 checks passed
@github-actions github-actions bot added this to the v0.4.0 milestone Jan 29, 2026
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