Skip to content

Conversation

@chenjiahan
Copy link
Member

@chenjiahan chenjiahan commented Sep 27, 2025

Summary

Simplify context management in the assets middleware:

  • use Rsbuild's context to get the build status
  • remove setupHooks file and move ready callback logic into middleware
  • remove the locals.webpack object, it's a experimental API of webpack-dev-middleware and not considered a public API for Rsbuild.

Related links

https://github.com/webpack/webpack-dev-middleware?tab=readme-ov-file#server-side-rendering

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings September 27, 2025 13:09
@netlify
Copy link

netlify bot commented Sep 27, 2025

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit ddf5da5
🔍 Latest deploy log https://app.netlify.com/projects/rsbuild/deploys/68d7e21976f0b40008ed2006
😎 Deploy Preview https://deploy-preview-6269--rsbuild.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 73 (🔴 down 3 from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: 60 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

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 simplifies context management in the assets middleware by using Rsbuild's internal context for build status tracking instead of maintaining separate ready state.

  • Removes the experimental locals.webpack object and setupHooks file
  • Consolidates ready callback logic directly into the middleware
  • Passes the full context instead of just environments to the middleware

Reviewed Changes

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

File Description
packages/core/src/server/buildManager.ts Updates assetsMiddleware call to pass full context instead of environments
packages/core/src/server/assets-middleware/setupHooks.ts Removes entire file that managed ready state and callbacks
packages/core/src/server/assets-middleware/middleware.ts Simplifies middleware by removing locals.webpack and using passed ready function
packages/core/src/server/assets-middleware/index.ts Consolidates ready callback logic and uses context.buildState for status checking

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

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

Comment on lines +244 to +248
const ready = (callback: () => void) => {
if (context.buildState.status === 'done') {
callback();
} else {
callbacks.push(callback);

Choose a reason for hiding this comment

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

[P1] Block dev requests when using a custom compiler

The middleware now waits for context.buildState.status === 'done' before invoking queued callbacks. buildState is only updated inside Rsbuild’s own createCompiler, but startDevServer still allows a caller-provided customCompiler (devServer.ts lines 182‑184) that never touches context.buildState. With a custom compiler the status remains idle, so the ready queue is never drained and every asset request hangs indefinitely. This is a regression from the previous hook-based Context which worked for arbitrary compilers. Consider falling back to compiler hooks when buildState isn’t driven by the given compiler or updating buildState when a custom compiler is supplied.

Useful? React with 👍 / 👎.

Copy link
Member Author

@chenjiahan chenjiahan Sep 28, 2025

Choose a reason for hiding this comment

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

I think customCompiler doesn't work properly in the previous implementation and needs to be deprecated

@chenjiahan chenjiahan merged commit d8685ae into main Sep 28, 2025
13 checks passed
@chenjiahan chenjiahan deleted the middleware_context_0927 branch September 28, 2025 02:09
@chenjiahan chenjiahan mentioned this pull request Sep 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants