Fix turnstile tab re-render and bump version

This commit is contained in:
Sora39831 2026-04-08 15:34:50 +08:00
parent 8a43a516ac
commit 8e9e36e1b8
3 changed files with 32 additions and 6 deletions

View file

@ -1 +1 @@
2.8.11
v1.3.4-beta

View file

@ -178,7 +178,7 @@
this.animationStarted = true;
this.initHeadline();
}
if (this.turnstileSiteKey) {
if (this.turnstileSiteKey && this.activeTab === 'register') {
this.ensureTurnstileRendered();
}
});
@ -191,11 +191,22 @@
},
methods: {
switchTab(key) {
if (key !== 'register') {
this.destroyTurnstile();
}
this.activeTab = key;
if (key === 'register') {
this.$nextTick(() => this.ensureTurnstileRendered());
}
},
destroyTurnstile() {
turnstileToken = '';
turnstileContainer = null;
if (window.turnstile && turnstileWidgetId !== null) {
turnstile.remove(turnstileWidgetId);
}
turnstileWidgetId = null;
},
async doLogin() {
this.loadingStates.spinning = true;
const msg = await HttpUtil.post('/login', this.user);
@ -224,13 +235,18 @@
this.activeTab = 'login';
this.user.username = this.regUser.username;
this.regUser = { username: "", password: "", confirmPassword: "" };
turnstileToken = '';
if (window.turnstile && turnstileWidgetId !== null) {
turnstile.reset(turnstileWidgetId);
}
this.destroyTurnstile();
}
this.loadingStates.registerSpinning = false;
},
isTurnstileContainerVisible(container) {
var pane = container.closest('.ant-tabs-tabpane');
if (!pane) {
return true;
}
var paneStyle = window.getComputedStyle(pane);
return paneStyle.display !== 'none' && paneStyle.visibility !== 'hidden';
},
ensureTurnstileRendered(retries = 20) {
if (!this.turnstileSiteKey) {
return;
@ -242,6 +258,12 @@
}
return;
}
if (!this.isTurnstileContainerVisible(container)) {
if (retries > 0) {
setTimeout(() => this.ensureTurnstileRendered(retries - 1), 150);
}
return;
}
if (
turnstileWidgetId !== null &&
(turnstileContainer !== container || container.childElementCount === 0)

View file

@ -18,6 +18,10 @@ func TestLoginTemplateRebuildsTurnstileAfterTabSwitch(t *testing.T) {
"turnstile.remove(turnstileWidgetId);",
"turnstileContainer !== container",
"turnstileToken = '';",
"this.activeTab === 'register'",
"!this.isTurnstileContainerVisible(container)",
"if (key !== 'register') {",
"this.destroyTurnstile();",
}
for _, check := range checks {