Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR improves how the Meteor Tool handles server crashes and build failures:
Uncaught SyntaxError: Unexpected token < in JSON at position 1
in the console!Video comparison of the current and the new version
Technical Details
The
autoupdate
package, which is responsible for notifying clients of changes, is used in both development and production. Therefore, it's part of the app and not the build tool. However, since the app server is terminated in case of a crash or build failure,autoupdate
cannot be used to reload the error page (see the following diagram).To solve this problem, the proxy opens an SSE endpoint (
/__meteor__/build-events
) that the app client and error page use to get notified of build events, which means that there are now two reload mechanisms: one for errors (via SSE) and one for regular rebuilds (via WebSocket/DDP). However, it might make sense to use SSE for regular rebuilds as well in the future.Future Work
Apps that need
autoupdate
/hot-code-push
only in development (some Apollo apps, for example) still have these packages and large dependencies (includingsocket-stream-client
andddp-client
) in their production bundles. This results in up to 90 kB of unused code as well as an unused WebSocket for each client. I've already reduced the size ofautoupdate
in #10238 by removing themongo
dependency but that's still a lot of overhead.However, I think it's possible to support both use cases in a backwards-compatible way. If
autoupdate
is included in the app, the Meteor Tool can use the current WebSocket/DDP-based reload for regular rebuilds. If the package is not included, it can let the proxy send a reload message to clients via SSE. That way, apps that useautoupdate
work exactly as they do now, whereas more lightweight apps don't need any additional packages for development-only reloads.