fix: only run middleware compiler in client env #5703
Merged
schiller-manuel(GitHub profile, opens in a new tab)merged 1 commit into
main fromrefs/pull/5703/head·merged by schiller-manuel(GitHub profile, opens in a new tab) Showing 1 changed file with 27 additions and 12 deletions.
x
27 additions and 12 deletions+27-12packages/start-plugin-core/src/start-compiler-plugin/compilers.tsModifiedView file
@@ -23,7 +23,7 @@
- const identifiers: Identifiers = {
+ const identifiers: Partial<Identifiers> = {
@@ -39,11 +39,16 @@
- createMiddleware: {
+ }
+
+ // createMiddleware only performs modifications in the client environment
+ // so we can avoid executing this on the server
+ if (opts.env === 'client') {
⚠️ Potential issue | 🟠 Major
Fix contradictory comment.
The comment states "avoid executing this on the client" but the condition opts.env === 'client' means the code WILL execute in the client environment. The comment should say "avoid executing this on the server" or be reworded for clarity.
Apply this diff to fix the comment:
- // createMiddleware only performs modifications in the client environment
- // so we can avoid executing this on the client
+ // createMiddleware only performs modifications in the client environment
+ // so we can avoid including it in the server build
if (opts.env === 'client') {
📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
// createMiddleware only performs modifications in the client environment
// so we can avoid including it in the server build
if (opts.env === 'client') {
🤖 Prompt for AI Agents
In packages/start-plugin-core/src/start-compiler-plugin/compilers.ts around
lines 44 to 46, the comment is contradictory: it says "avoid executing this on
the client" while the if condition checks opts.env === 'client' (meaning it runs
on the client). Update the comment to correctly describe the behavior — e.g.,
"createMiddleware only performs modifications in the client environment so we
can avoid executing this on the server" or reword to state that the block runs
only for the client — ensuring the comment matches the condition.
✅ Addressed in commit c7cfa35