fix: update functional components in hmr.reload()#52
Open
jonaskuske wants to merge 1 commit intovitejs:mainfrom
Open
fix: update functional components in hmr.reload()#52jonaskuske wants to merge 1 commit intovitejs:mainfrom
jonaskuske wants to merge 1 commit intovitejs:mainfrom
Conversation
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.
An SFC functional component that does not use
<template functional>will go through__VUE_HMR_RUNTIME__.reload()instead of.rerender(), because the plugin can't detect thefunctional template attrto inject its_rerender_onlymarker.After updating the component's options, the reload function will still try to reload it by updating its parent via
$vnode.context. This causes two issues:instancealready points to the component's (stateful) parent. In turn, the functional component's grandparent is updated, which does not cause the functional component down the tree to rerender. (unless props changed) So the update does not appear on the screen until maybe later some other condition causes a rerender:instancewill point to the root. The runtime notices that the instance has no parent context (which would be the child's grandparent) and issues a warning about unsupported root HMR instead of updating the child:To fix this, this PR makes
__VUE_HMR_RUNTIME__.reloadcall.$forceUpdate()on the instance itself instead of on the parent context if the reloaded component is functional.