Fix Vite 8 (Rolldown/OXC) transform error in CopyPageButton script - #408
Fix Vite 8 (Rolldown/OXC) transform error in CopyPageButton script#408hongyi-chen wants to merge 1 commit into
Conversation
Astro compiles client `<script>` blocks into virtual modules tagged `?astro&type=script&index=0&lang.ts` and relies on the transformer to strip TypeScript. With Astro 7 now pulling in Vite 8 (Rolldown-powered, using the OXC transformer instead of esbuild), OXC infers the language from the real `.astro` extension rather than the `lang.ts` query, so it parses the script as plain JS and rejects the TS-only syntax with `[PARSE_ERROR] Type assertion expressions can only be used in TypeScript files`. Convert the three bits of TS-only syntax in the script block to JSDoc casts (valid JS that OXC accepts) so the type info is preserved for `astro check` while `npm run dev`/`build` succeed on Vite 8: - `as HTMLTemplateElement | null` -> `/** @type {...} */ (...)` - `(e: MouseEvent)` -> `/** @param {MouseEvent} e */` - `e.target as Node` -> `/** @type {Node} */ (e.target)` Verified with a clean `astro dev` startup and a full `astro build` (exit 0, no vite:oxc parse errors) on Vite 8.1.5 + Rolldown 1.1.5 + Astro 7.1.3. Co-Authored-By: Oz <oz-agent@warp.dev>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
I'm starting a first review of this pull request. You can view the conversation on Warp. I completed the review and no human review was requested for this pull request. Comment Powered by Oz |
There was a problem hiding this comment.
Overview
This PR updates CopyPageButton.astro so the bundled client script avoids TypeScript-only syntax that Vite 8/OXC parses incorrectly from Astro virtual script modules. The replacement JSDoc casts preserve the intended DOM types while keeping the emitted script valid JavaScript.
Concerns
- No blocking correctness, security, or spec-alignment concerns found in the annotated diff.
Verdict
Found: 0 critical, 0 important, 0 suggestions
Approve
Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).
Powered by Oz
Problem
Running the docs dev server fails for anyone on a fresh install with a Vite transform error:
Root cause
Astro compiles client
<script>blocks into virtual modules tagged?astro&type=script&index=0&lang.tsand relies on the transformer to strip TypeScript.astro@7.1.3now pulls in Vite 8 (Rolldown-powered, using the OXC transformer instead of esbuild — notePlugin: vite:oxc). OXC infers the language from the real.astrofile extension rather than thelang.tsquery suffix, so it parses the script as plain JS and rejects the TS-only syntax inCopyPageButton.astro.This is why it hits "someone else" and not everyone: devs with older
node_modulesstill have Vite 7 (esbuild), which handledlang.tscorrectly. A clean install (npm ci) lands on Vite 8.1.5 + Rolldown/OXC and breaks.Fix
CopyPageButton.astrois the only processed (bundled)<script>in the repo containing TS-only syntax — every other script isis:inline(untransformed) or already plain JS. Convert its three bits of TS syntax to JSDoc casts, which are valid JS that OXC accepts while preserving the type info forastro check:as HTMLTemplateElement | null→/** @type {HTMLTemplateElement | null} */ (...)(e: MouseEvent)→/** @param {MouseEvent} e */e.target as Node→/** @type {Node} */ (e.target)Runtime behavior is unchanged.
Verification
On the exact reproducing stack (Vite 8.1.5 + Rolldown 1.1.5 + Astro 7.1.3):
npm run dev -- --forcestarts cleanly with novite:oxc/[PARSE_ERROR].npm run buildcompletes with exit 0 (full OXC transform of all client scripts), no parse/transform errors.Conversation: https://staging.warp.dev/conversation/d5fabfce-7be4-4574-b96b-0faa9a8ea1ec
Run: https://oz.staging.warp.dev/runs/019faacc-1953-76c9-8392-d925b72c068d
This PR was generated with Oz.