Nested JSX components under React Server Components: derive flat exports from the signature
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- javascript, next.js, react
- Ambito
- compilers
Direzione di ricerca
Start by reviewing #8886 and its linked review, then trace how the compiler derives exports from signatures and rewrites nested .make paths. The issue proposes a signature-based naming rule, but leaves JSX-only versus all-read rewriting and dynamic imports open. Done means resolving those design questions and verifying the export behavior across the listed bundlers and optimization modes.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
🤖 Drafted with Claude (Claude Code), based on the review of #8886.
Problem
Nested components such as <Sidebar.Provider /> compile to a read through the module object:
import * as Sidebar from "./Sidebar.mjs";
JsxRuntime.jsx(Sidebar.Provider.make, …)
Under React Server Components, a server component can only use a client module's top-level exports. Sidebar.Provider is already a client reference, so reading .make on it fails ("You cannot dot into a client module from a server component"). Nested components from "use client" files therefore can't be used from server components (e.g. Next.js App Router).
Previous attempts:
- #8293: PoC rewriting JSX component paths to flat exports.
- #8402:
@res.hoistedFunctionplus a.cmjtable of hoisted exports, as the first step. - #8886: automatic hoisting of nested components on top of #8402.
Why the current approach is fragile
In #8402/#8886, whether a flat export exists depends on the producer's implementation, and it is recorded only in the producer's .cmj. Consumers compile against the .cmi, and both build systems rebuild dependents only when the .cmi changes. With a .resi, an edit that touches only the implementation (e.g. adding let make = React.memo(make)) removes Provider$make while the .cmi stays byte-identical. Already-compiled consumers then read undefined and React throws "Element type is invalid". The same applies to adding or removing @res.hoistedFunction in a .res file.
Most other issues found in the review of #8886 follow from the same design: components that are silently skipped, the JsxExternal rewrite (lost @deprecated/@genType, false reanalyze reports, rename bug, lost imports), property-read aliases that defeat tree-shaking, and linear lookups in the .cmj table. See https://github.com/rescript-lang/rescript/pull/8886#pullrequestreview-5562112336 for details.
Proposal
Use one fixed naming rule that both sides derive from the signature only:
Every
makein a nested module that is visible in the file's final signature is also exported asA$B$make.
- Producer: walk the signature after the
.resihas been applied. For each suchmake, addexport { <existing binding> as A$B$make }. This adds no statement, so tree-shaking is unaffected. Only a module with no static binding (a functor application or an unpacked first-class module) gets aconst A$B$make = A.B.makefallback. Relative externals are covered because the producer already exposes them as values. Package externals are unaffected because consumers import them directly. - Consumer: compile
Global.A.B.makeasGlobal.A$B$make, based purely on the shape of the path. No.cmjlookup. - Clash:
module A$B = {let make}next toA.B.makewould both map toA$B$make. Report a compile error in the producer. - Remove
@res.hoistedFunction, the.cmjtable of hoisted exports, and the related lookup code. They have only shipped inv13.0.0-alpha.6.
The export set then changes exactly when the .cmi changes, so rebuilding when the .cmi changes stays correct. No marker on the component definition, no identity checks, and no gating on "use client" are needed.
Open questions
- Rewrite every nested
.makeread, or only JSX element types? Rewriting every read is simpler and also covers components passed as props. Restricting it to JSX element types needs a marker attribute from the JSX transform. Either way,jest.spyOn(Lib.Trigger, "make")andvi.mockfactories written against the module object would no longer intercept, which should get a changelog note. - Dynamic imports:
module D = await Libbinds a module namespace, soD.Provider.makecould becomeD.Provider$makeas well. - To verify: unused extra export names are free in esbuild/Rolldown/webpack/Turbopack, and the consumer-side path rewrite works with cross-module optimization both on and off.
- Lingua principale
- ReScript
- Stelle
- 7.5k
- Fork
- 483
- Merge medio
- 1g 2h
- PR unite (30g)
- 147
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- 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 rescript-lang/rescript
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
rescript-lang/rescript#8910 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
rescript-lang/rescript#8897 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
rescript-lang/rescript#8878 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
rescript-lang/rescript#8806 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
rescript-lang/rescript#8798 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di rescript-lang/rescript
Issue simili
-
bug priority: P2
Difficoltà 1/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno
-
clang:static analyzer
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
llvm/llvm-project#233598 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
AeneasVerif/aeneas#1467 ·
I maintainer di solito rispondono entro 1 giorno
-
arrays asr pass enhancement format I/O low priority
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
I maintainer di solito rispondono entro 1 giorno