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: only call callback when needed @W-17420330 #5064

Merged
merged 3 commits into from
Dec 19, 2024
Merged
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
1 change: 1 addition & 0 deletions packages/@lwc/engine-core/src/framework/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export { registerTemplate } from './secure-template';
export { registerDecorators } from './decorators/register';

// Mics. internal APIs -----------------------------------------------------------------------------
export { BaseBridgeElement } from './base-bridge-element';
export { unwrap } from './membrane';
export { sanitizeAttribute } from './secure-template';
export { getComponentDef, isComponentConstructor } from './def';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
runFormDisabledCallback,
runFormResetCallback,
runFormStateRestoreCallback,
BaseBridgeElement,
} from '@lwc/engine-core';
import { isNull } from '@lwc/shared';
import { renderer } from '../renderer';
Expand Down Expand Up @@ -121,7 +122,10 @@ export function buildCustomElementConstructor(Ctor: ComponentConstructor): HTMLE
}

attributeChangedCallback(name: string, oldValue: any, newValue: any) {
attributeChangedCallback.call(this, name, oldValue, newValue);
if (this instanceof BaseBridgeElement) {
// W-17420330
attributeChangedCallback.call(this, name, oldValue, newValue);
}
}

formAssociatedCallback(form: HTMLFormElement | null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import TimingParent from 'timing/parent';
import TimingParentLight from 'timing/parentLight';
import ReorderingList from 'reordering/list';
import ReorderingListLight from 'reordering/listLight';
import Details from 'x/details';

function resetTimingBuffer() {
window.timingBuffer = [];
Expand Down Expand Up @@ -422,3 +423,16 @@ describe('dispatchEvent from connectedCallback/disconnectedCallback', () => {
expect(globalDisconnected).toBe(false); // never received due to disconnection
});
});

describe('attributeChangedCallback', () => {
it('W-17420330 - only fires for registered component', async () => {
const root = createElement('x-details', { is: Details });
document.body.appendChild(root);
await Promise.resolve();

const details = root.shadowRoot.querySelector('details');
const cb = Details.CustomElementConstructor.prototype.attributeChangedCallback;
cb.call(details, 'open', '', 'open');
expect(details.getAttribute('open')).toBeNull();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<template>
<details>
<summary>An Ode to Toads</summary>
<p>
Violets are red,<br>
Roses are blue,<br>
Toads are cool!
</p>
</details>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { LightningElement, api } from 'lwc';

export default class Details extends LightningElement {
@api open;
}