Skip to content

Commit 680b12e

Browse files
johnjenkinsJohn Jenkins
andauthored
fix(runtime): stop immediate re-renders for reflected props when null !== undefined (#6404)
* fix: local (same-file) class inheritance search * fix(runtime): stop immediate re-renders for null !== undefined * chore: add test * chore: lint --------- Co-authored-by: John Jenkins <john.jenkins@nanoporetech.com>
1 parent 695b1ac commit 680b12e

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/runtime/proxy-component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ export const proxyComponent = (
344344
// test whether this property either has no 'getter' or if it does, does it also have a 'setter'
345345
// before attempting to write back to component props
346346
newValue = newValue === null && typeof this[propName] === 'boolean' ? (false as any) : newValue;
347-
if (newValue !== this[propName] && (!propDesc.get || !!propDesc.set)) {
347+
if (newValue != this[propName] && (!propDesc.get || !!propDesc.set)) {
348348
this[propName] = newValue;
349349
}
350350
});

src/runtime/test/prop-warnings.spec.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,28 @@ describe('prop', () => {
125125

126126
expect(spy).not.toHaveBeenCalled();
127127
});
128+
129+
it('should not show warning setting reflected prop to undefined', async () => {
130+
@Component({ tag: 'cmp-a' })
131+
class CmpA {
132+
@Prop({ reflect: true }) a = 1;
133+
134+
render() {
135+
return `${this.a ? this.a : ''}`;
136+
}
137+
}
138+
139+
const { root, waitForChanges } = await newSpecPage({
140+
components: [CmpA],
141+
html: `<cmp-a></cmp-a>`,
142+
});
143+
144+
expect(root).toEqualHtml('<cmp-a a="1">1</cmp-a>');
145+
146+
root.a = undefined;
147+
await waitForChanges();
148+
149+
expect(root).toEqualHtml('<cmp-a></cmp-a>');
150+
expect(spy).not.toHaveBeenCalled();
151+
});
128152
});

0 commit comments

Comments
 (0)