Repository navigation
capnweb-validate: keep a module's hashbang and directive prologue first - #279
Open
martijnwalraven wants to merge 1 commit into
Open
martijnwalraven wants to merge 1 commit into
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 |
Contributor
|
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. |
Author
|
I have read the CLA Document and I hereby sign the CLA. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.