⚡ Bolt: Optimize static asset serving with async streams#99
⚡ Bolt: Optimize static asset serving with async streams#99Dexploarer wants to merge 1 commit intomainfrom
Conversation
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
| setTimeout(() => { | ||
| mockFileStream.push(Buffer.from("css content")); | ||
| mockFileStream.push(null); // End of stream | ||
| }, 10); |
There was a problem hiding this comment.
Nondeterministic test due to setTimeout for stream completion
The use of setTimeout to push data to the mock file stream in the test may cause nondeterministic behavior and flakiness:
setTimeout(() => {
mockFileStream.push(Buffer.from("css content"));
mockFileStream.push(null); // End of stream
}, 10);If the test runner resolves the promise before the stream is fully pushed, the test may intermittently fail. Replace setTimeout with synchronous stream manipulation or use proper async handling (e.g., await events.once(mockFileStream, 'end')) to ensure reliable test execution.
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Summary of ChangesHello @Dexploarer, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the performance and scalability of static asset serving within the application. By transitioning from synchronous to asynchronous file operations and leveraging Node.js streams, the server can now handle static content requests more efficiently, reducing event loop blocking and improving overall responsiveness, especially in production environments. The changes are thoroughly validated with new dedicated tests. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
The refactoring of serveStaticUi to use asynchronous filesystem operations and streams is a significant improvement for the server's performance and responsiveness. By using fs.promises.stat and pipeline with fs.createReadStream, the Node.js event loop is no longer blocked during file I/O, which is critical for serving static assets under load. The addition of unit tests and the _resetUiDirForTest helper ensures the new logic is verified and maintainable. I have one recommendation regarding error handling during streaming to prevent potential 'Headers already sent' errors.
| await pipeline(fs.createReadStream(candidatePath), res); | ||
| return true; | ||
| } | ||
| } catch { |
There was a problem hiding this comment.
The current try-catch block is too broad. If the pipeline fails after res.writeHead has already been called (for example, if the client disconnects prematurely), the execution will enter the catch block and proceed to the SPA fallback logic at line 1767. This will attempt to call res.writeHead again via sendStaticResponse, resulting in a ERR_HTTP_HEADERS_SENT error and potentially crashing the request handler. We should check if headers have already been sent before allowing the fallback to proceed.
} catch (err) {
if (res.headersSent) {
return true;
}
Refactored
serveStaticUiinsrc/api/server.tsto use asynchronous filesystem operations (fs.promises.statandfs.createReadStreamwithpipeline). This prevents the Node.js event loop from blocking while serving static UI assets in production mode, improving concurrency and responsiveness under load.Included
src/api/server.static.test.tsto verify the new async behavior and edge cases (e.g. file not found falling back to SPA index). ExportedserveStaticUiand added_resetUiDirForTestto facilitate testing.PR created automatically by Jules for task 13203585560154505481 started by @Dexploarer