Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Nested JSX components under React Server Components: derive flat exports from the signature

Abierto
#8,901 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@cknitt ya está trabajando en esto.

Desde el 18/10/2026.

  • #8904 de @cknitt — abierto

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
25/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
javascript, next.js, react
Área
compilers

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

🤖 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.hoistedFunction plus a .cmj table 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 make in a nested module that is visible in the file's final signature is also exported as A$B$make.

  • Producer: walk the signature after the .resi has been applied. For each such make, add export { <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 a const A$B$make = A.B.make fallback. 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.make as Global.A$B$make, based purely on the shape of the path. No .cmj lookup.
  • Clash: module A$B = {let make} next to A.B.make would both map to A$B$make. Report a compile error in the producer.
  • Remove @res.hoistedFunction, the .cmj table of hoisted exports, and the related lookup code. They have only shipped in v13.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

  1. Rewrite every nested .make read, 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") and vi.mock factories written against the module object would no longer intercept, which should get a changelog note.
  2. Dynamic imports: module D = await Lib binds a module namespace, so D.Provider.make could become D.Provider$make as well.
  3. 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.
Lenguaje dominante
ReScript
Estrellas
7.5k
Forks
483
Merge medio
1 d 2 h
PR fusionados (30 d)
147

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de rescript-lang/rescript

Todos los issues de rescript-lang/rescript

Issues similares

Más issues de Compilers

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.