Repository navigation
capnweb-validate: keep a module's hashbang and directive prologue first - #279
martijnwalraven wants to merge 1 commit into
Conversation
The transform inserted its runtime import and validators at offset zero.
In a module that begins with a directive such as "use client" the directive
was then no longer in the prologue, so frameworks stopped reading it, and in
a module that begins with a hashbang the result did not parse ("'#!' can
only be used at the start of a file"). The insert now goes after the
hashbang and the last directive.
🦋 Changeset detectedLatest commit: 5079f8c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
|
I have read the CLA Document and I hereby sign the CLA. |
|
@clanky-the-clanker review this |
|
✅ Approved — No issues found. The decision is advisory: this comment never approves, blocks or requests changes on the pull request. ✅ All checks passed📋 Code Quality: ✅ LGTMI found no problems in
📝 Documentation: ✅ LGTMThe changeset entry and the new code comment both describe the behaviour change accurately. Reviewed commit: |
The transform inserts its runtime import and generated validators at offset zero of a module. Two kinds of module break on that:
"use client"in a Next.js app, loses it from the directive prologue once an import sits above it, so the framework no longer treats the module as a client component. The symptom in Next.js 16 is a decorated class in a"use client"file compiling as a server module.'#!' can only be used at the start of a file).This moves the insert to after the hashbang and after the last directive of the prologue, in
preludeEdit. Nothing else in the transform changes.Tested with three cases in
transform-module.test.ts, each parsing the output: a prologue of two directives after a comment, a hashbang alone, and a hashbang followed by directives; a string literal after an import is left where it is, since it is no directive. Found while running the transform under Turbopack in a Next.js 16.3.6 app, where the"use client"case showed up first.Changeset: patch for
capnweb-validate.