perf: remove schema-utils dependency and validation#12
Conversation
Summary of ChangesHello, 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 focuses on a performance improvement by eliminating the 'schema-utils' dependency and all related option validation infrastructure. This change aims to reduce the bundle size and runtime overhead, making the middleware more lightweight and efficient. The removal encompasses the schema definition, validation calls, and corresponding test files, simplifying the codebase. 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
This pull request successfully removes the schema-utils dependency and its associated validation logic to improve performance. The changes are applied consistently across the codebase, including updates to dependencies, removal of schema and test files, and adjustments to type definitions.
However, the complete removal of option validation is a significant concern. It makes the middleware less robust and can lead to a poor developer experience due to cryptic runtime errors on invalid configuration. I have left a comment in src/index.js suggesting the addition of basic, manual validation for options. This would provide a good compromise, maintaining most of the performance gains while preventing hard-to-debug issues for users.
| @@ -198,11 +195,6 @@ const noop = () => {}; | |||
| * @returns {API<RequestInternal, ResponseInternal>} webpack dev middleware | |||
| */ | |||
| function wdm(compiler, options = {}) { | |||
There was a problem hiding this comment.
Removing options validation entirely may lead to cryptic runtime errors and a poor developer experience when invalid options are provided. For instance, if a user passes a non-object value for mimeTypes, it will result in an unhelpful TypeError when the options are used.
While removing the schema-utils dependency is beneficial for performance, I recommend adding basic manual checks for the options. This would provide clear error messages for common misconfigurations and strike a better balance between performance and robustness.
For example:
if (options.mimeTypes && (typeof options.mimeTypes !== 'object' || Array.isArray(options.mimeTypes))) {
throw new Error('The "mimeTypes" option must be an object.');
}There was a problem hiding this comment.
Pull request overview
This PR removes the schema-utils dependency and all associated validation logic from webpack-dev-middleware. This eliminates runtime schema validation of options passed to the middleware, reducing bundle size and startup overhead at the cost of losing developer-friendly validation error messages for invalid configuration.
Changes:
- Removed
schema-utilsfrom dependencies and deleted theoptions.jsonschema definition - Removed the
validate()call in thewdm()entry point and cleaned up related type definitions - Deleted the validation test file and its snapshots, and added
pnpm-lock.yamlto.prettierignore
Reviewed changes
Copilot reviewed 6 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/index.js | Removed schema-utils import, schema import, and validate() call |
| src/options.json | Deleted JSON schema definition file |
| types/index.d.ts | Removed Schema type references |
| tsconfig.json | Removed resolveJsonModule (no longer needed without options.json) |
| package.json | Removed schema-utils from dependencies |
| test/validation-options.test.js | Deleted validation test suite |
| test/snapshots/validation-options.test.js.snap.webpack5 | Deleted validation test snapshots |
| .prettierignore | Added pnpm-lock.yaml to ignore list |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 028fabdb6d
ℹ️ 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 "@codex address that feedback".
| @@ -198,11 +195,6 @@ const noop = () => {}; | |||
| * @returns {API<RequestInternal, ResponseInternal>} webpack dev middleware | |||
| */ | |||
| function wdm(compiler, options = {}) { | |||
There was a problem hiding this comment.
Restore option validation before middleware setup
Removing the validation step in wdm lets malformed options reach request-time code paths that assume validated types, which now causes hard runtime failures instead of an immediate config error. For example, passing methods: true will now initialize successfully but throw on the first request when acceptedMethods.includes(...) is executed in src/middleware.js (line 169), and modifyResponseData: true will be invoked as a function in src/middleware.js (lines 814-817). This is a regression from startup ValidationError behavior and can crash production traffic on misconfiguration.
Useful? React with 👍 / 👎.
The commit removes the schema-utils dependency and all related validation code, including: