Skip to content

fix(vite): preserve typed plugin return values - #188

Merged
tannerlinsley merged 2 commits into
mainfrom
taren/type-vite-plugin
Nov 25, 2026
Merged

tannerlinsley merged 2 commits into
mainfrom
taren/type-vite-plugin

Conversation

@tannerlinsley

@tannerlinsley tannerlinsley commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Keep typed Vite configs and type-aware lint rules working with redact(). Thanks to @WolfieLeader for reporting this.

AI review notes:
The factory now returns its inferred plugin array and checks it against Vite's plugin contract. Literal hook ordering stays typed, newer environment hooks stay visible, and public declarations avoid an optional Vite type dependency. This also avoids the duplicate Node declaration failure found with a direct Plugin[] annotation.

The built-declaration regression rejects the old any signature and checks both exports, nested plugin arrays and spread usage. Full local CI passed: 2,128 tests, 91 skipped, types, strict build verification and all 38 fixed size caps. All 36 comparisons against current main are unchanged. Clean consumers passed with Vite 5.4.21, 6.4.6, 7.3.8 and 8.3.5, TypeScript 5.9.3 and skipLibCheck: false.

No runtime dependencies, workflows or budget limits changed. Existing tests use the same partial-context hook harness pattern as the other Vite tests.

Fixes #185

CI follow-up:
The development HMR check failed after restoring a route file, with a missing server context and lost counter state. A controlled 200 ms incomplete write also broke the unchanged fixture with native React. The fixture now uses Vite's supported completed-write watcher mode, with no assertion or timeout changes.

The controlled write passes for native React and Redact on Chromium, Firefox and WebKit. The ordinary development and production checks also pass on all three engines. Local container copies only adapt Chromium's launch sandbox setting for the existing isolated root container; the shipped script is unchanged. This verifies the reproduced incomplete-write case, the original hosted missing-context outcome still needs the normal CI rerun. The package source and all measured size rows remain unchanged.

Summary by CodeRabbit

  • Bug Fixes
    • redact() now returns Vite plugins with usable TypeScript types instead of any.
    • Improved fixture stability when reading updated modules during hot reload.

@changeset-bot

changeset-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f13c883

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@tanstack/redact Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Vite redact() function now infers its plugin-array return type and checks the array against Vite’s Plugin type. Tests check the built declaration’s types, locate plugins with a shared helper, and configure file-write polling in a fixture.

Changes: Vite return typing

Layer / File(s) Summary
Infer and check the plugin array
packages/redact/src/vite/index.ts, .changeset/typed-vite-plugin.md
redact() now returns an inferred plugin array checked with satisfies Array<Plugin>. Literal enforce and order values use as const. The changeset describes the return-type update.
Validate plugin typing and selection
tests/vite-plugin-types.test.ts, tests/vite-environments.test.ts, tests/fixtures/react-router-framework/vite.config.js
A consumer test checks the built declaration’s return types and Vite config compatibility. Environment tests use a shared helper to find named plugins. The fixture server polls for file-write completion before HMR reads updated modules.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to f13c8

This change makes the Vite plugin return a typed plugin array instead of any, with tests covering the built declaration. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title 'fix(vite): preserve typed plugin return values' matches the main change. The changeset and the redact() source change make the inferred plugin array the return type instead of any, and a ne…
Linked Issues check Passed Only directly linked issue #185 applies. Its coding requirement is that redact() from @tanstack/redact/vite stop returning any, so typed Vite configs keep plugin checking. The previous review fo…
Out of Scope Changes check Passed The incremental change since the previous review adds a watcher option (server.watch.awaitWriteFinish with stabilityThreshold: 300 and pollInterval: 10) to the React Router framework fixture's V…
Full details: Title check

Explanation

The title 'fix(vite): preserve typed plugin return values' matches the main change. The changeset and the redact() source change make the inferred plugin array the return type instead of any, and a new test checks that the declared return type is not any and is assignable to Plugin[]. The title names the scope (vite) and the fix (typed return values). It does not mention the HMR fixture change, which is a minor follow-up and not the primary change.

Full details: Linked Issues check

Explanation

Only directly linked issue #185 applies. Its coding requirement is that redact() from @tanstack/redact/vite stop returning any, so typed Vite configs keep plugin checking. The previous review found this met at the reviewed head: the : any return annotation is removed, the function returns an inferred plugin array, and return plugins satisfies Array&lt;Plugin&gt; checks the array against Vite's Plugin type. enforce and order use as const, and applyToEnvironment and filter stay in the inferred shape. The incremental diff from the previous reviewed head (41e99a9) to head (f13c883) changes only tests/fixtures/react-router-framework/vite.config.js. It does not touch the source or declaration code, so the prior conclusion still holds. The new tests/vite-plugin-types.test.ts checks the built declaration, but it does not exercise the no-unsafe-assignment lint rule directly. PR-reported CI and Vite-version consumer results were not re-run in this review.

Full details: Out of Scope Changes check

Explanation

The incremental change since the previous review adds a watcher option (server.watch.awaitWriteFinish with stabilityThreshold: 300 and pollInterval: 10) to the React Router framework fixture's Vite config. It is test-fixture configuration only, with no runtime package change. The PR description and objectives describe this as a CI follow-up for the HMR fixture, so it is part of the stated PR scope, although it is not directly tied to #185. The earlier in-scope changes (source typing, tests/vite-plugin-types.test.ts, tests/vite-environments.test.ts helper, and the changeset) remain connected to #185. No demonstrated unrelated change was found.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 886c47db-498c-4b03-8346-b4e7d2c5e7d6
Commits

Reviewing files that changed from the base of the PR and between 41e99a9 and f13c883.

Files selected for processing: 1

  • tests/fixtures/react-router-framework/vite.config.js

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@tannerlinsley
tannerlinsley merged commit 61ad375 into main Nov 25, 2026
66 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 25, 2026
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.

redact() from @tanstack/redact/vite returns any

1 participant