Skip to content

Commit db660bb

Browse files
authored
fix: display captcha correctly on initial load (#162)
修复首次加载评论时,不能正常显示验证码的问题。 Fixes #160 /kind bug ```release-note 修复首次加载评论时,不能正常显示验证码的问题。 ```
1 parent 3ab7d2f commit db660bb

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

packages/comment-widget/src/base-form.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ export class BaseForm extends LitElement {
7878
return this.captchaEnabled && !this.currentUser && this.allowAnonymousComments;
7979
}
8080

81+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
82+
override updated(changedProperties: Map<string, any>) {
83+
if (
84+
changedProperties.has('captchaEnabled') ||
85+
changedProperties.has('currentUser') ||
86+
changedProperties.has('allowAnonymousComments')
87+
) {
88+
if (this.showCaptcha) {
89+
this.handleFetchCaptcha();
90+
}
91+
}
92+
}
93+
8194
async handleFetchCaptcha() {
8295
if (!this.showCaptcha) {
8396
return;
@@ -143,7 +156,6 @@ export class BaseForm extends LitElement {
143156
override connectedCallback(): void {
144157
super.connectedCallback();
145158
this.addEventListener('keydown', this.onKeydown);
146-
this.handleFetchCaptcha();
147159
}
148160

149161
override disconnectedCallback(): void {

0 commit comments

Comments
 (0)