Resolve local function exports for file directive export validation
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 45/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Tranquilla
- Stack tecnologico
- typescript
- Ambito
- build-system, tooling
Direzione di ricerca
Inizia da module-export-scan.ts e usa PR #1380 come riferimento per l’implementazione e i test. Aggiungi una copertura di integrazione mirata di module-export-scan e delle direttive per le funzioni locali risolte, i binding non risolti e la convalida a livello di file di "use server" o "use cache", verificando anche gli snapshot esistenti di wrapper, effetti, filtraggio e source map. Il lavoro è completato quando i callback possono convalidare staticamente i nodi di funzione locale risolti senza che le trasformazioni generiche impongano la policy delle direttive.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
- related to https://github.com/vitejs/vite-plugin-react/pull/1380
- related to https://github.com/vitejs/vite-plugin-react/issues/1335
Motivation
The inline directive alignment tracked by #1335 can expose a Next.js-aligned function validator and let directive owners apply it through existing transform callbacks:
runtime(value, name, meta) {
validateDirectiveFunction(meta.valueNode, directive)
return wrap(value, name)
}
This composes with transformHoistInlineDirective, transformModuleExportEffect, and transformWrapExport without baking Server Function policy into generic transforms.
For module directives, however, validation is only as complete as ModuleExportMeta.valueNode. Direct declarations and function-valued initializers expose their function node, but locally exported bindings do not currently resolve back to their declaration.
For example:
'use server'
async function action() {
console.log(arguments)
}
export { action }
and:
'use cache'
const cached = async function () {
console.log(arguments)
}
export default cached
The transform can register or wrap these exports, but callback metadata does not expose the source function node, so a directive owner cannot apply the same validation used for a direct export.
Next.js Behavior
Next.js performs a module prepass that maps exported local identifiers to export names. Exported functions then inherit the file-level "use server" or "use cache" directive before the function visitor checks this, super, and arguments.
This means validation does not depend on whether the function is written directly inside an export declaration or exported later through a local identifier. Non-exported functions do not inherit the file directive.
Error fixtures 23 and 24 in next-custom-transforms demonstrate the exported versus non-exported distinction and the lexical traversal rules. The local-binding prepass is implemented in server_actions.rs through export_name_by_local_id.
Prior Work
PR #1380 prototyped local function export resolution in module-export-scan.ts. It covered local aliases, default identifiers, exports before declarations, and direct-function metadata. The PR was closed in favor of #1387, which retained a simpler export-wrapper implementation and did not land local binding resolution.
Use #1380 as an implementation and test reference, but separate metadata discovery from its callable-rewriting requirements.
Proposed Direction
Extend module export scanning with an explicit representation for a statically resolved local function source.
Cover:
- Function declarations exported through local specifiers.
constbindings initialized with function expressions or arrows and exported through local specifiers.- Local aliases such as
export { action as renamed }. - Default identifier exports such as
export default action. - Exports appearing before their local declaration.
- Multiple export names referring to the same local function.
Do not assume that changing ModuleExportMeta.valueNode is necessarily the right API. It is currently documented as unavailable for export specifiers, and external consumers may rely on that distinction. Compare these shapes:
- Populate
valueNodeafter local resolution. - Add separate
resolvedValueNodemetadata. - Restore a narrow
directFunctionrepresentation similar to #1380. - Expose a separate local-binding resolver consumed by directive-aware integrations.
Prefer the smallest shape that lets transform callbacks validate the source function without coupling scanning to wrapper production.
Integration
Once a local function node is available, existing directive integrations should feed it into the same validator used for direct exports:
- Built-in file-level
"use server"throughtransformServerActionServer. - Framework-owned file-level
"use cache"throughtransformWrapExportor the preferred module wrapper transform. - Other custom Server Function directives using module export transform callbacks.
transformModuleExportEffect and transformWrapExport should remain generic. They should expose metadata but should not enforce this, super, or arguments restrictions themselves.
Semantics To Check
- Local export specifiers are live bindings, while default identifier exports have different binding behavior.
- Imported bindings and source re-exports do not have a local function body and must remain unresolved.
- Arbitrary call-expression initializers are not statically known functions.
- Mutable bindings can stop referring to their initial function, so metadata must not overstate certainty.
- Destructured declarations should remain unknown rather than assigning the container initializer to each binding.
- Duplicate aliases should not cause duplicate source rewriting or inconsistent validation.
- Metadata enrichment must not unexpectedly change existing
filterbehavior in public transform consumers.
Verification
Add focused module-export-scan and directive integration coverage for:
- Function declaration followed by a local export specifier.
- Local export before the function declaration.
constarrow and function-expression exports.- Renamed local exports.
- Default identifier exports.
- Multiple aliases of one local function.
- Imported bindings, re-exports, mutable bindings, call-expression initializers, and destructuring remaining unresolved where appropriate.
- File-level
"use server"and"use cache"validation rejectingthis,super, orargumentsthrough resolved local exports. - Non-exported functions remaining outside file-directive validation.
- Existing module wrapper, effect, filtering, and source-map snapshots remaining stable unless a deliberate metadata change requires updates.
Non-goals
- Changing inline method lowering from #1335.
- Baking directive validation into generic export transforms.
- Redesigning canonical callable production or local wrapped-binding semantics; coordinate those changes with #1350.
- Resolving functions across module boundaries.
- Changing proxy generation, reference manifests, closure transport, or cache policy.
- Lingua principale
- TypeScript
- Stelle
- 1.2k
- Fork
- 287
- Merge medio
- 1g 17h
- PR unite (30g)
- 19
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di vitejs/vite-plugin-react
-
plugin-rsc: a client reference's CSS is linked before the CSS of the chunks it imports (build)Forse già presa @wozhenbang2004 l’ha presa 7 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
vitejs/vite-plugin-react#1570 ·
I maintainer di solito rispondono entro 1 giorno
-
pending triage
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
vitejs/vite-plugin-react#1581 ·
I maintainer di solito rispondono entro 1 giorno
-
[plugin-rsc] Build exits 0, but the app fails at runtime: a server action imported only by browser code is missing from the RSC buildForse già presa @NeilPant l’ha presa 4 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
vitejs/vite-plugin-react#1578 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
vitejs/vite-plugin-react#1577 ·
I maintainer di solito rispondono entro 1 giorno
-
[plugin-rsc] inline "use server" function declarations lose hoisting and throw TDZ ReferenceErrorForse già presa @draarivpatel-ui l’ha presa 3 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
vitejs/vite-plugin-react#1566 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di vitejs/vite-plugin-react
Issue simili
-
good first issue help wanted
Difficoltà 2/5 Meno di un'ora Idoneità per principianti 86/100
Intelligenza-Umana/intelligenza-umana-web#16 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
open-webui/open-webui#35184 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
danielmiessler/LifeOS#3001 ·
I maintainer di solito rispondono entro 5 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno