Skip to content

Conversation

@lightninglu10
Copy link
Contributor

@lightninglu10 lightninglu10 commented Dec 3, 2025

Add skipProviderWrap option and Next.js auto-detection to avoid __CPProvider injection

This PR adds a configurable and auto-detected way to skip wrapping components with __CPProvider for frameworks like Next.js that manage HMR differently.

Key Changes:

  • Introduce skip_provider_wrap field in CodePressTransform
  • Parse config key skipProviderWrap (boolean) with fallback auto-detection via presence of next.config.js/ts/mjs
  • Gate ensure_provider_inline and JSX provider wrapping on !skip_provider_wrap
  • Retain env map and stamp helper injection behavior

Review Notes:

  • Default behavior changes in environments with next.config.* present; can be overridden via config
  • Consider edge cases in monorepos or non-standard working directories for the auto-detect logic

@lightninglu10 lightninglu10 self-assigned this Dec 3, 2025
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

❇️ CodePress Review Summary

👋 Hey team,

Overall the changes look solid, but I spotted 1 must-fix issue and left 0 helpful notes inline.

Here's the quick rundown:

✅ Decision: APPROVE
The change is cohesive and consistently gates provider usage and injection. No clear blocking correctness, security, or perf issues are evident; potential mis-detection risks are non-blocking and can be mitigated by explicit config.

🚧 Needs a bit of love

The Next.js auto-detection that governs skip_provider_wrap misses projects using next.config.cjs, which remain common in CJS and older Node setups. This omission can misclassify Next.js apps, leaving skip_provider_wrap disabled and injecting __CPProvider, potentially disrupting HMR and router-driven refresh behavior. Including next.config.cjs in the detection logic would prevent these false negatives and improve compatibility across Next.js configurations.

import_resolver,
env_vars,
inserted_env_map: false,
skip_provider_wrap,
Copy link

Choose a reason for hiding this comment

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

🔴 REQUIRED: The auto-detection for Next.js that drives skip_provider_wrap omits next.config.cjs. Many projects (especially older/Node CJS setups) use next.config.cjs; failing to detect it will leave skip_provider_wrap=false and still inject __CPProvider under Next.js. That can break HMR behavior and potentially user code relying on Next’s router-driven refresh. Please include next.config.cjs in the detection to avoid false negatives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants