From db660bb34940833562b1ad087f54fb27fbc37d8f Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Mon, 28 Oct 2024 11:34:03 +0800 Subject: [PATCH] fix: display captcha correctly on initial load (#162) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复首次加载评论时,不能正常显示验证码的问题。 Fixes https://github.com/halo-dev/plugin-comment-widget/issues/160 /kind bug ```release-note 修复首次加载评论时,不能正常显示验证码的问题。 ``` --- packages/comment-widget/src/base-form.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/comment-widget/src/base-form.ts b/packages/comment-widget/src/base-form.ts index c80799d..460b92a 100644 --- a/packages/comment-widget/src/base-form.ts +++ b/packages/comment-widget/src/base-form.ts @@ -78,6 +78,19 @@ export class BaseForm extends LitElement { return this.captchaEnabled && !this.currentUser && this.allowAnonymousComments; } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + override updated(changedProperties: Map) { + if ( + changedProperties.has('captchaEnabled') || + changedProperties.has('currentUser') || + changedProperties.has('allowAnonymousComments') + ) { + if (this.showCaptcha) { + this.handleFetchCaptcha(); + } + } + } + async handleFetchCaptcha() { if (!this.showCaptcha) { return; @@ -143,7 +156,6 @@ export class BaseForm extends LitElement { override connectedCallback(): void { super.connectedCallback(); this.addEventListener('keydown', this.onKeydown); - this.handleFetchCaptcha(); } override disconnectedCallback(): void {