Skip to content

Commit

Permalink
Fix afterRerender sometimes throws error (#8449)
Browse files Browse the repository at this point in the history
  • Loading branch information
dk981234 authored Jun 21, 2024
1 parent c06841c commit ffd6b45
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ export class Base {
return this.supportOnElementRenderedEvent && this.onElementRenderedEventEnabled ? this._onElementRerendered : undefined;
}
public afterRerender(): void {
this.onElementRerendered.fire(this, undefined);
this.onElementRerendered?.fire(this, undefined);
}
}

Expand Down
15 changes: 15 additions & 0 deletions tests/basetests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -816,3 +816,18 @@ QUnit.test("check animationAllowed", function (assert) {
assert.ok(question.animationAllowed);
settings.animationEnabled = false;
});

QUnit.test("check afterRerender function", (assert) => {
const survey = new SurveyModel({});
assert.notOk(!!survey.onElementRerendered);
survey.afterRerender();
survey.enableOnElementRenderedEvent();
let log = "";
survey.onElementRerendered.add(() => log += "->callback");
survey.afterRerender();
assert.equal(log, "->callback");
log = "";
survey.disableOnElementRenderedEvent();
survey.afterRerender();
assert.equal(log, "");
});

0 comments on commit ffd6b45

Please sign in to comment.