fix: false reactive component warning (#9094)

fixes #9082
pull/9121/head
gtmnayan 1 year ago committed by GitHub
parent 93b17c85f7
commit 26eb2a2f89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: silence false positive reactive component warning

@ -105,14 +105,19 @@ export default class InlineComponentWrapper extends Wrapper {
this.slots.set(name, slot_definition); this.slots.set(name, slot_definition);
} }
warn_if_reactive() { warn_if_reactive() {
const { name } = this.node; let { name } = this.node;
const variable = this.renderer.component.var_lookup.get(name); const top = name.split('.')[0]; // <T.foo/> etc. should check for T instead of "T.foo"
const variable = this.renderer.component.var_lookup.get(top);
if (!variable) { if (!variable) {
return; return;
} }
const ignores = extract_ignores_above_node(this.node); const ignores = extract_ignores_above_node(this.node);
this.renderer.component.push_ignores(ignores); this.renderer.component.push_ignores(ignores);
if (variable.reassigned || variable.export_name || variable.is_reactive_dependency) { if (
variable.reassigned ||
variable.export_name || // or a prop
variable.mutated
) {
this.renderer.component.warn(this.node, compiler_warnings.reactive_component(name)); this.renderer.component.warn(this.node, compiler_warnings.reactive_component(name));
} }
this.renderer.component.pop_ignores(); this.renderer.component.pop_ignores();

Loading…
Cancel
Save