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: trigger componentUpdateFn twice when props updated #250

Closed
wants to merge 1 commit 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export let activeEffect: ReactiveEffect | undefined

export class ReactiveEffect<T = any> {
constructor(public fn: () => T) {}
allowRecurse?: boolean

run() {
let parent: ReactiveEffect | undefined = activeEffect
Expand Down Expand Up @@ -42,6 +43,9 @@ export function trigger(target: object, key?: unknown) {
if (dep) {
const effects = [...dep]
for (const effect of effects) {
if (!effect.allowRecurse) {
continue
}
effect.run()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ export function createRenderer(options: RendererOptions) {
next.component = instance
instance.vnode = next
instance.next = null
toggleRecurse(instance, false)
updateProps(instance, next.props)
toggleRecurse(instance, true)
} else {
next = vnode
}
Expand All @@ -200,6 +202,7 @@ export function createRenderer(options: RendererOptions) {

const effect = (instance.effect = new ReactiveEffect(componentUpdateFn))
const update = (instance.update = () => effect.run())
toggleRecurse(instance, true)
update()
}

Expand All @@ -216,3 +219,10 @@ export function createRenderer(options: RendererOptions) {

return { render }
}

function toggleRecurse(
{ effect }: ComponentInternalInstance,
allowed: boolean,
) {
effect.allowRecurse = allowed
}