feat: allow HMR in server builds - #34
Merged
Merged
Conversation
`hotReload: true` now opts a server build into hot reload as well, so a dev server that renders on the server can hot swap modules instead of restarting the whole process. Server builds stay opt-in: without the flag nothing changes, and `hotReload: false` still wins. Addresses both issues raised in the review of rstackjs#32: - A server build imports `ssrRender`, but the generated template update callback called `api.rerender(id, render)`, which threw `ReferenceError: render is not defined`. `api.rerender` cannot handle `ssrRender` either - it assigns whatever it is given to `render` and re-renders the mounted instances, which a server build does not have. The new function is written back to the component definition instead, which is the object parent modules hold on to. - The imported-type watch hook only invalidated `clientCache`, so a server build kept rendering with the stale compiled script after an imported prop type changed. Both caches are invalidated now. Tests drive a real watching server build: they render through `vue/server-renderer`, edit a template or an imported type, apply the hot update the way a dev server would, and render again.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Follow-up to #32 (review) - the server HMR part of #32, with both issues you found fixed.
hotReload: trueopts a server build into hot reload. Still a no-op without it, andhotReload: falsekeeps winning.api.rerender(id, render)in a server build.renderisn't imported there, andapi.rerendercan't takessrRendereither - it assigns whatever it gets torenderand re-renders the mounted instances, which a server build doesn't have (only the DOM renderer registers them). The callback writes the newssrRenderback onto the component definition instead, which is the object parent modules hold on to.serverCacheas well, not justclientCache.test/serverHotReload.spec.tsdrives a watching server build: it renders throughvue/server-renderer, edits a template / an imported type, applies the hot update the way a dev server would, and renders again. Both cases fail without the fixes above -render is not definedand stale props respectively.