remix: Dev Server crashes if saving before the last rebuild complete

What version of Remix are you using?

v1.19.0

Are all your remix dependencies & dev-dependencies using the same version?

  • Yes

Steps to Reproduce

This is somewhat inconsistent, since it depends in part how quickly your server rebuilds.

This most frequently occurs when working on our production apps with longer rebuild time (https://github.com/manawiki/starrail) and CTRL+S save rapidly before rebuilds are ready.

The error usually looks like this:

 info  rebuilding... (~ app/routes/_index.tsx)
 info  rebuilt (167ms)
 info  app server ready (9ms)
 info  hmr

 info  rebuilding... (~ app/routes/_index.tsx)
 info  rebuilt (291ms)
 info  rebuilding... (~ app/routes/_index.tsx)
 info  app server ready (37ms)
 info  hmr


/node_modules/@remix-run/server-runtime/dist/dev.js:26
      buildHash: build.assets.version
                              ^
TypeError: Cannot read properties of undefined (reading 'version')
    at broadcastDevReady (/node_modules/@remix-run/server-runtime/dist/dev.js:26:31)
    at FSWatcher.<anonymous> (file:///server.js:64:5)
 info  rebuilt (511ms)

I’ll try to see if I can create a reproducible step with a simpler template.

Expected Behavior

Dev Server crashes gracefully.

Actual Behavior

Dev Server crash and force a manual restart.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 4
  • Comments: 29 (25 by maintainers)

Commits related to this issue

Most upvoted comments

@chankruze the fixes were merged after v2.0.0. they are available on nightly (npx upgrade-remix nightly) if you want to try them out. They’ll be included in the next release.

After v2 releases, we can update the templates to watch for version.txt and then close this issue

@pcattori I thought of another way to handle this than using awaitWriteFinish on chokidar… Since chokidar in the server is only watching a single file, if the build saved to a temporary file, and then when saving was done, rename/move the file to the target file name, replacing the old one, it would be an almost atomic action, and reloading should take place without a hitch.

Fixed by #7469 and #7470

For now, let’s rely on awaitWriteFinish. After v2 releases, I’ll look into this some more.

@xHomu Adding back in awaitWriteFinish and still watching metafile.server.json wouldn’t prove anything because it would then be relying on the timing of 200 ms (or whatever the configuration is set to). for the index.js to finish being written. It would be mostly a coincidence if it worked.

Watching "./build/metafile.server.json" (and removing awaitWriteFinish) isn’t working for me. The server re-imports, but on a manual refresh of the browser, the server is now trying to serve up the old missing chunks to the browser.

The HMR also seemed to stop working as the new chunks aren’t loading.

I’m on Remix 1.19.2.

My reading of this is that the metadata is written out before the bytes in the outputFiles:

https://github.com/remix-run/remix/blob/8779b24d0e51cc49a887d16afab9789557b80124/packages/remix-dev/compiler/server/compiler.ts#L143-L147

@pcattori I pushed the WATCH_PATH change to mana.wiki and seems to be working at least as well as watching BUILD_PATH, will report back if we saw any instability https://github.com/manawiki/core/commit/2b81f4d2f8744d1bb14ac2fbf784c9719f11f22b#comments

so far so good

Sure let me give that a shot today. Should I go ahead and close pr #6922 until we settle on best practices?

Just made it into a Draft PR for now