[perf][bug] disable no-ssr and fix hCaptcha rendering in SSR

This commit is contained in:
Andrea 2022-02-13 23:19:06 +01:00
parent e8823c320a
commit ebb408ae8d
4 changed files with 17 additions and 17 deletions

View File

@ -1,5 +1,5 @@
<template> <template>
<div style="height: 73px"></div> <div style="height: 73px" @click="render"></div>
</template> </template>
<script> <script>
@ -11,19 +11,19 @@
value: {}, value: {},
}, },
async mounted() { async mounted() {
if (!process.client) { if (!process.client) { return; }
return false; await this.$loadScript('hcaptcha', `https://js.hcaptcha.com/1/api.js?hl=${this.config.locale}`);
} setTimeout(() => { this.render() }, 500);
},
await this.$loadScript('hcaptcha', 'https://js.hcaptcha.com/1/api.js'); methods: {
render() {
if (!window.hcaptcha || this.$el.innerHTML.length) { return; }
window.hcaptcha.render(this.$el, { window.hcaptcha.render(this.$el, {
sitekey: process.env.HCAPTCHA_SITEKEY, sitekey: process.env.HCAPTCHA_SITEKEY,
theme: this.detectDark() ? 'dark' : 'light', theme: this.detectDark() ? 'dark' : 'light',
callback: this.solved, callback: this.solved,
}); });
}, },
methods: {
solved(token) { solved(token) {
this.$emit('input', token); this.$emit('input', token);
}, },

View File

@ -24,7 +24,7 @@
<Icon v="info-circle"/> <Icon v="info-circle"/>
<T>captcha.reason</T> <T>captcha.reason</T>
</p> </p>
<Captcha class="h-captcha" v-model="captchaToken"/> <Captcha v-model="captchaToken"/>
<button class="btn btn-primary mt-3 d-none d-md-block" :disabled="!canInit"> <button class="btn btn-primary mt-3 d-none d-md-block" :disabled="!canInit">
<Icon v="sign-in"/> <Icon v="sign-in"/>
<T>user.login.action</T> <T>user.login.action</T>

View File

@ -51,7 +51,7 @@
sorter(); sorter();
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === 'production') {
//this.monkeyPatchBlockTrackers(['google-analytics.com', 'tkr.arc.io', 'browser.sentry-cdn.com',]); this.monkeyPatchBlockTrackers(['google-analytics.com', 'tkr.arc.io', 'browser.sentry-cdn.com',]);
this.$loadScript('arc', 'https://arc.io/widget.min.js#yHdNYRkC'); this.$loadScript('arc', 'https://arc.io/widget.min.js#yHdNYRkC');
} }

View File

@ -14,8 +14,8 @@ const isBrowser = (userAgent) => {
} }
export default function(req, res, next) { export default function(req, res, next) {
if (process.env.NODE_ENV === 'production' && !req.url.startsWith('/card/@')) { // if (process.env.NODE_ENV === 'production' && !req.url.startsWith('/card/@')) {
res.spa = isBrowser(req.headers['user-agent']) || isHighLoadTime(process.env.LOCALE); // res.spa = isBrowser(req.headers['user-agent']) || isHighLoadTime(process.env.LOCALE);
} // }
next(); next();
} }