webpack-dev-server icon indicating copy to clipboard operation
webpack-dev-server copied to clipboard

Refactor webpack-dev-server middleware application logic

Open Swapnilden opened this issue 1 year ago • 0 comments

This commit refactors the middleware application logic in the webpack-dev-server codebase to ensure that middleware is applied only once, regardless of how many times it's called.

Previously, certain middleware, such as static serving middleware, was being applied multiple times to support features like historyApiFallback. This refactor eliminates duplicate middleware application by introducing a mechanism to track applied middleware and applying each middleware only once.

Changes:

  • Introduced appliedMiddleware array to track applied middleware.
  • Created applyMiddlewareOnce function to apply middleware only if it hasn't been applied before.
  • Updated webpack-dev-server codebase to utilize applyMiddlewareOnce for applying middleware associated with various features.

This update aims to improve code efficiency and prevent unintended behavior or performance issues caused by duplicate middleware application.

Fixes: #2716

  • [ ] This is a bugfix
  • [ ] This is a feature
  • [x] This is a code refactor
  • [ ] This is a test update
  • [ ] This is a docs update
  • [ ] This is a metadata update

For Bugs and Features; did you add new tests?

Motivation / Use-Case

Breaking Changes

Additional Info

Swapnilden avatar Apr 11 '24 05:04 Swapnilden