Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hmr): force full diff props for nested component coming from npm. (fix: #5767) #5781

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions packages/runtime-core/__tests__/hmr.spec.ts
Expand Up @@ -469,4 +469,28 @@ describe('hot module replacement', () => {
render(h(Foo), root)
expect(serializeInner(root)).toBe('bar')
})

// #5767
test('rerender for nested component coming from an external npm package with static props', () => {
const id = 'parent'
const Child: ComponentOptions = {
props: {
msg: String
},
render: compileToFunction(`<div>{{msg}}</div><slot/>`)
}
const Parent: ComponentOptions = {
__hmrId: id,
components: { Child },
render: compileToFunction(`<Child msg="outer"><Child msg="inner" /></Child>`)
}

createRecord(id, Parent)
const root = nodeOps.createElement('div')
render(h(Parent), root)
expect(serializeInner(root)).toBe(`<div>outer</div><div>inner</div>`)

rerender(id, compileToFunction(`<Child msg="outer"><Child msg="in" /></Child>`))
expect(serializeInner(root)).toBe(`<div>outer</div><div>in</div>`)
})
})
5 changes: 2 additions & 3 deletions packages/runtime-core/src/componentProps.ts
Expand Up @@ -40,6 +40,7 @@ import { createPropsDefaultThis } from './compat/props'
import { isCompatEnabled, softAssertCompatEnabled } from './compat/compatConfig'
import { DeprecationTypes } from './compat/compatConfig'
import { shouldSkipAttr } from './compat/attrsFallthrough'
import { isHmrUpdating } from './hmr'

export type ComponentPropsOptions<P = Data> =
| ComponentObjectPropsOptions<P>
Expand Down Expand Up @@ -211,9 +212,7 @@ export function updateProps(
// - #1942 if hmr is enabled with sfc component
// - vite#872 non-sfc component used by sfc component
!(
__DEV__ &&
(instance.type.__hmrId ||
(instance.parent && instance.parent.type.__hmrId))
__DEV__ && isHmrUpdating
) &&
(optimized || patchFlag > 0) &&
!(patchFlag & PatchFlags.FULL_PROPS)
Expand Down