Skip to content

Commit

Permalink
R1: schedule amp-bind targets (#37619)
Browse files Browse the repository at this point in the history
  • Loading branch information
samouri committed Feb 11, 2022
1 parent 9609fe3 commit 616859e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/custom-element.js
Expand Up @@ -1800,6 +1800,11 @@ function createBaseCustomElementClass(win, elementConnectedCallback) {
mutatedAttributesCallback(mutations) {
if (this.impl_) {
this.impl_.mutatedAttributesCallback(mutations);
} else if (this.R1()) {
// If amp-bind is trying to mutate an uninitialized BaseElement, it is probably about time
// to initialize it.
const scheduler = getSchedulerForDoc(this);
scheduler.scheduleAsap(this);
}
}

Expand Down
8 changes: 8 additions & 0 deletions test/unit/test-custom-element-v1.js
Expand Up @@ -625,6 +625,14 @@ describes.realWin('CustomElement V1', {amp: true}, (env) => {
await element.buildInternal();
await promise;
});

it('should build if amp-bind mutation', async () => {
const element = new ElementClass();
builderMock.expects('scheduleAsap').withExactArgs(element).once();

doc.body.appendChild(element);
element.mutatedAttributesCallback({});
});
});

describe('mount/unmount', () => {
Expand Down

0 comments on commit 616859e

Please sign in to comment.