Feature: let a config hold a hot-reload update until a build the change started has written its output
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- javascript, react-native
Línea de trabajo
Read the cited HmrServer.js update flow and IncrementalBundler.js graph-update logic, along with the reproduction repository's metro.config.js and test.js. Start by tracing how updates are computed for both hot reload and repeated bundle requests; determine how an awaited config hook could include files written by the build. Done means a supported option produces one update containing both screen.js and generated.js in the reproduction.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Do you want to request a feature or report a bug?
A feature.
What is the current behavior?
A tool that derives a module from other files (a CSS compiler, a code generator) hears a change, runs its build and writes its output, a module the app imports. Metro computes the hot-reload update for the change that started the build on its own schedule: HmrServer debounces the delta bundler's change events by 50 ms and then calls IncrementalBundler.updateGraph (HmrServer.js#L193-L206, #L363), which takes only the changes the file map has reported by then (IncrementalBundler.js#L292-L303). Unless the build finishes inside the debounce, its output reaches the file map as a later change and goes out in a second update, so for one update the app runs the changed module against the old generated one: a class name with no styles yet, a call into a generated module that does not have the new export.
Nothing public lets a config make an update wait for that build. A file map plugin's onChanged returns void (flow-types.js#L309), serializer.experimentalSerializerHook runs after the delta is computed and is not awaited (IncrementalBundler.js#L305), and server.unstable_onServerCreated hands over the server with no hook on its updates. The only way I found is replacing updateGraph on the server's IncrementalBundler with a method that first waits for the build and for the file map to report what it wrote.
If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install and yarn test.
It is not a bug, but this repository shows the two updates: https://github.com/YevheniiKotyrlo/metro-hold-update-for-generated-module
index.js requires screen.js, which names a class, and generated.js, which holds the styles for it. build.js stands in for the tool: whenever screen.js changes, it writes generated.js from it, taking 300 ms. test.js starts Metro with metro.config.js, requests the bundle, registers it on /hot, changes the class in screen.js, and prints each update until one carries generated.js.
yarn install
yarn test
yarn test:held
yarn test:
Metro 0.87.2, no hold
bundle: HTTP 200
edited screen.js: className card -> banner
update 1: screen.js
update 2: generated.js
FAIL: the update carrying screen.js does not carry generated.js
yarn test:held, where metro.config.js replaces updateGraph as described above:
Metro 0.87.2, updates held
bundle: HTTP 200
edited screen.js: className card -> banner
update 1: screen.js, generated.js
PASS: screen.js and generated.js arrived in one update
That is the reproduction at fb66b7330c on Metro 0.87.2. main at a87d864565, built into the reproduction's node_modules with PACKAGES_DIR=<reproduction>/node_modules node scripts/build.js, prints the same in three runs of each.
What is the expected behavior?
A supported way for a config to make Metro's next update wait for work a change started, for every update Metro computes (HmrServer's and a repeated bundle request's). For example, an async server option Metro awaits before it computes a delta, resolving to the files the work wrote, which Metro then takes into that delta:
// metro.config.js
module.exports = {
server: {
// The name and shape are only a sketch.
unstable_beforeUpdate: async () => {
await builds.settled();
return [generatedPath];
},
},
};
With it, the reproduction's yarn test would print one update carrying screen.js and generated.js, as yarn test:held does today.
#1902 (cross-file transform inputs) and #2036 (virtual modules from the resolver) are related: virtual modules would let generated source skip the file system, but neither orders an update after the build that produces that source.
Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system.
The configuration is metro.config.js in the repository. Metro 0.87.2 and main at a87d864565, Node 26.12.1, Yarn 1.22.22, Windows 11.
- Lenguaje dominante
- JavaScript
- Estrellas
- 5.7k
- Forks
- 711
- Merge medio
- 3 d 14 h
- PR fusionados (30 d)
- 77
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de react/metro
-
[metro-file-map] An error a watcher backend reports ends the server, since nothing listens for itPosiblemente ocupada @sorinc03 la tomó hace 2 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
Los mantenedores suelen responder en 1 día
-
Resolver: Read `exports` from the package root, not the closest `package.json`Posiblemente ocupada @robhogan la tomó hoy. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 22/100
react/metro#2153 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
Los mantenedores suelen responder en 1 día
-
metro-file-map gives up on a fallback watcher that is still starting after a fixed 240 s, and leaves it runningPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
Los mantenedores suelen responder en 1 día
Todos los issues de react/metro
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
help wanted Idea 💡 wdio-cli
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
webdriverio/webdriverio#16361 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
clientV2: Application Info header separators show as missing-character boxes without a CJK fontAbiertobug new-client
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
NUWCDIVNPT/stig-manager#2285 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
Fei2411/DeepSeek-Bot#922 · 1 reacción ·
-
Workers AI integration drops output of non-streaming chat responses in the OpenAI format (`choices`)AbiertoBug Cloudflare Workers Spans
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
getsentry/sentry-javascript#26120 · 1 comentario ·
Los mantenedores suelen responder en 1 día