Skip to content

Commit

Permalink
fix: Add Safari compatibility for requestIdleCallback (#9435)
Browse files Browse the repository at this point in the history
  • Loading branch information
scmmishra committed May 8, 2024
1 parent 9977bcc commit 6c5b137
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions app/javascript/v3/views/login/Index.vue
@@ -1,32 +1,32 @@
<template>
<main
class="flex flex-col bg-woot-25 min-h-screen w-full py-20 sm:px-6 lg:px-8 dark:bg-slate-900"
class="flex flex-col w-full min-h-screen py-20 bg-woot-25 sm:px-6 lg:px-8 dark:bg-slate-900"
>
<section class="max-w-5xl mx-auto">
<img
:src="globalConfig.logo"
:alt="globalConfig.installationName"
class="mx-auto h-8 w-auto block dark:hidden"
class="block w-auto h-8 mx-auto dark:hidden"
/>
<img
v-if="globalConfig.logoDark"
:src="globalConfig.logoDark"
:alt="globalConfig.installationName"
class="mx-auto h-8 w-auto hidden dark:block"
class="hidden w-auto h-8 mx-auto dark:block"
/>
<h2
class="mt-6 text-center text-3xl font-medium text-slate-900 dark:text-woot-50"
class="mt-6 text-3xl font-medium text-center text-slate-900 dark:text-woot-50"
>
{{
useInstallationName($t('LOGIN.TITLE'), globalConfig.installationName)
}}
</h2>
<p
v-if="showSignupLink"
class="mt-3 text-center text-sm text-slate-600 dark:text-slate-400"
class="mt-3 text-sm text-center text-slate-600 dark:text-slate-400"
>
{{ $t('COMMON.OR') }}
<router-link to="auth/signup" class="text-link lowercase">
<router-link to="auth/signup" class="lowercase text-link">
{{ $t('LOGIN.CREATE_NEW_ACCOUNT') }}
</router-link>
</p>
Expand Down Expand Up @@ -68,7 +68,7 @@
<p v-if="!globalConfig.disableUserProfileUpdate">
<router-link
to="auth/reset/password"
class="text-link text-sm"
class="text-sm text-link"
tabindex="4"
>
{{ $t('LOGIN.FORGOT_PASSWORD') }}
Expand Down Expand Up @@ -165,14 +165,27 @@ export default {
const message = ERROR_MESSAGES[this.authError] ?? 'LOGIN.API.UNAUTH';
this.showAlert(this.$t(message));
// wait for idle state
window.requestIdleCallback(() => {
this.requestIdleCallbackPolyfill(() => {
// Remove the error query param from the url
const { query } = this.$route;
this.$router.replace({ query: { ...query, error: undefined } });
});
}
},
methods: {
// TODO: Remove this when Safari gets wider support
// Ref: https://caniuse.com/requestidlecallback
//
requestIdleCallbackPolyfill(callback) {
if (window.requestIdleCallback) {
window.requestIdleCallback(callback);
} else {
// Fallback for safari
// Using a delay of 0 allows the callback to be executed asynchronously
// in the next available event loop iteration, similar to requestIdleCallback
setTimeout(callback, 0);
}
},
showAlert(message) {
// Reset loading, current selected agent
this.loginApi.showLoading = false;
Expand Down

0 comments on commit 6c5b137

Please sign in to comment.