Skip to content

fix(redact/vite): respect 'forwardRef' and 'classComponents' feature flags#15

Open
sukvvon wants to merge 1 commit into
TanStack:mainfrom
sukvvon:fix/vite-feature-flag-kebab-case-mapping
Open

fix(redact/vite): respect 'forwardRef' and 'classComponents' feature flags#15
sukvvon wants to merge 1 commit into
TanStack:mainfrom
sukvvon:fix/vite-feature-flag-kebab-case-mapping

Conversation

@sukvvon
Copy link
Copy Markdown
Contributor

@sukvvon sukvvon commented May 13, 2026

The Vite plugin's feature-flag swap was a silent no-op for two flags:
forwardRef: false and classComponents: false. Other flags
(portal, context, suspense, memo, lazy) worked because their
folder names happen to match the ResolvedFeatures key 1:1.

Root cause

features/index.ts imports each feature by its on-disk folder name:

import './forward-ref'
import './class'

The resolveId hook receives the bare specifier (./forward-ref,
./class) and used to cast it directly to keyof ResolvedFeatures:

const name = m[1] as keyof ResolvedFeatures
if (name in features && !features[name]) { ... }

ResolvedFeatures uses camelCase (forwardRef, classComponents), so
'forward-ref' in features and 'class' in features are both false
— the swap branch never ran and the full feature implementation stayed
in the bundle even when the user opted out.

Fix

Introduce an explicit folder → key mapping. The resolve() call still
uses the folder name (it's a disk path), but the feature lookup uses
the mapped camelCase key.

const FOLDER_TO_FEATURE: Record<string, keyof ResolvedFeatures> = {
  portal: 'portal',
  context: 'context',
  suspense: 'suspense',
  memo: 'memo',
  'forward-ref': 'forwardRef',
  lazy: 'lazy',
  class: 'classComponents',
}

Test plan

  • New tests/vite-plugin-feature-swap.test.ts — 5 regression cases
    covering both kebab-mapped flags, the five identity-mapped flags,
    the "flag on → no swap" path, and the RSC environment skip
  • Reverting the fix makes the forward-ref and class cases fail,
    confirming the test catches the regression
  • pnpm --filter tests test — all green
  • pnpm test:types — clean

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.

1 participant