Skip to content

Commit d72a760

Browse files
Merge pull request #323 from appwrite/fix-flicker
Fix FOUC
2 parents 394b49e + fb7e7e9 commit d72a760

File tree

9 files changed

+71
-96
lines changed

9 files changed

+71
-96
lines changed

src/app.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
<body class="theme-dark" data-sveltekit-preload-data="hover">
2121
<script>
22+
// Theme
2223
const isDocs = window.location.pathname.startsWith('/docs');
2324
if (isDocs) {
2425
const theme = localStorage.getItem('theme');
@@ -35,6 +36,16 @@
3536
}
3637
}
3738
}
39+
40+
// Progressive enhancement
41+
document.body.dataset.jsEnabled = '';
42+
43+
// Banner
44+
const BANNER_KEY = '%aw_banner_key%';
45+
const hideBanner = localStorage.getItem(BANNER_KEY);
46+
if (hideBanner === 'true') {
47+
document.body.dataset.bannerHidden = '';
48+
}
3849
</script>
3950
<div style="display: contents">%sveltekit.body%</div>
4051
</body>

src/hooks/server.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
import type { Handle } from '@sveltejs/kit';
22
import redirects from './redirects.json';
3+
import { sequence } from '@sveltejs/kit/hooks';
4+
import { BANNER_KEY } from '$lib/constants';
35

46
const redirectMap = new Map(redirects.map(({ link, redirect }) => [link, redirect]));
57

6-
export const handle: Handle = async ({ event, resolve }) => {
7-
const currentPath = event.url.pathname;
8-
if (redirectMap.has(currentPath)) {
9-
return new Response(null, {
10-
status: 308,
11-
headers: {
12-
location: redirectMap.get(currentPath) ?? ''
13-
}
14-
});
15-
}
8+
const redirecter: Handle = async ({ event, resolve }) => {
9+
const currentPath = event.url.pathname;
10+
if (redirectMap.has(currentPath)) {
11+
return new Response(null, {
12+
status: 308,
13+
headers: {
14+
location: redirectMap.get(currentPath) ?? ''
15+
}
16+
});
17+
}
1618

17-
return await resolve(event);
19+
return await resolve(event);
1820
};
21+
22+
const bannerRewriter: Handle = async ({ event, resolve }) => {
23+
const response = await resolve(event, {
24+
transformPageChunk: ({ html }) => html.replace('%aw_banner_key%', BANNER_KEY)
25+
});
26+
return response;
27+
};
28+
29+
export const handle = sequence(redirecter, bannerRewriter);

src/lib/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const BANNER_KEY = 'discord-banner-01'; // Change key to force banner to show again

src/lib/layouts/Main.svelte

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212
<script lang="ts">
1313
import { browser } from '$app/environment';
1414
import { MobileNav } from '$lib/components';
15+
import { BANNER_KEY } from '$lib/constants';
1516
import { isVisible } from '$lib/utils/isVisible';
1617
import { createScrollInfo } from '$lib/utils/scroll';
1718
import { addEventListener } from '@melt-ui/svelte/internal/helpers';
1819
import { onMount } from 'svelte';
19-
import { slide } from 'svelte/transition';
20-
import { persisted } from '$lib/utils/persisted';
2120
2221
let theme: 'light' | 'dark' | null = 'dark';
2322
@@ -112,11 +111,10 @@
112111
return $scrollInfo.deltaDirChange < 200;
113112
})();
114113
115-
const BANNER_KEY = 'discord-banner-00'; // Change this key whenever you want to show the banner again for all users
116-
let showTopBanner = persisted(BANNER_KEY, {
117-
defaultValue: true,
118-
validate: (value): value is boolean => typeof value === 'boolean'
119-
});
114+
const hideTopBanner = () => {
115+
document.body.dataset.bannerHidden = '';
116+
localStorage.setItem(BANNER_KEY, 'true');
117+
};
120118
</script>
121119

122120
<div class="u-position-relative">
@@ -163,30 +161,28 @@
163161
</div>
164162
</section>
165163
<header
166-
class="aw-main-header is-special-padding theme-{resolvedTheme}"
167-
class:is-transparent={browser}
164+
class="aw-main-header is-special-padding theme-{resolvedTheme} is-transparent"
168165
class:is-hidden={$isHeaderHidden}
169166
>
170-
{#if $showTopBanner}
171-
<div class="aw-top-banner" transition:slide={{ duration: 250 }}>
172-
<div class="aw-top-banner-content aw-u-color-text-primary">
173-
<a href="/discord" target="_blank" rel="noopener noreferrer">
174-
<span class="aw-caption-500">We are having lots of fun on</span>
175-
<span class="aw-icon-discord" aria-hidden="true" />
176-
<span class="aw-caption-500">Discord. Come and join us!</span>
177-
</a>
178-
{#if browser}
179-
<button
180-
class="aw-top-banner-button"
181-
aria-label="close discord message"
182-
on:click={() => ($showTopBanner = false)}
183-
>
184-
<span class="aw-icon-close" aria-hidden="true" />
185-
</button>
186-
{/if}
187-
</div>
167+
<div class="aw-top-banner">
168+
<div class="aw-top-banner-content aw-u-color-text-primary">
169+
<a href="/discord" target="_blank" rel="noopener noreferrer">
170+
<span class="aw-caption-500">We are having lots of fun on</span>
171+
<span class="aw-icon-discord" aria-hidden="true" />
172+
<span class="aw-caption-500">Discord. Come and join us!</span>
173+
</a>
174+
{#if browser}
175+
<button
176+
class="aw-top-banner-button"
177+
aria-label="close discord message"
178+
on:click={hideTopBanner}
179+
>
180+
<span class="aw-icon-close" aria-hidden="true" />
181+
</button>
182+
{/if}
188183
</div>
189-
{/if}
184+
</div>
185+
190186
<div class="aw-main-header-wrapper">
191187
<div class="aw-main-header-start">
192188
<a href="/">

src/routes/api/blog/+server.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/routes/docs/references/+layout.svelte

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
<script lang="ts" context="module">
2-
export function getReferencesContext() {
3-
return getContext<Writable<boolean>>('references-expandable');
4-
}
5-
</script>
6-
71
<script lang="ts">
82
import { page } from '$app/stores';
93
import Docs from '$lib/layouts/Docs.svelte';
10-
import { preferredPlatform, preferredVersion } from '$lib/utils/references';
11-
import { writable, type Writable } from 'svelte/store';
12-
import { getContext, setContext } from 'svelte';
134
import Sidebar, { type NavParent, type NavTree } from '$lib/layouts/Sidebar.svelte';
5+
import { preferredPlatform, preferredVersion } from '$lib/utils/references';
146
15-
const expandable = setContext('references-expandable', writable(false));
7+
$: expandable = !!$page.url.pathname.match(/\/docs\/references\/.*?\/.*?\/.*?\/?/);
168
179
$: prefix = `/docs/references/${$preferredVersion ?? $page.params?.version ?? 'cloud'}/${
1810
$preferredPlatform ?? $page.params?.platform ?? 'client-web'
@@ -96,7 +88,7 @@
9688
};
9789
</script>
9890

99-
<Docs variant={$expandable ? 'expanded' : 'two-side-navs'} isReferences={$expandable}>
100-
<Sidebar {navigation} expandable={$expandable} {parent} />
91+
<Docs variant={expandable ? 'expanded' : 'two-side-navs'} isReferences={expandable}>
92+
<Sidebar {navigation} {expandable} {parent} />
10193
<slot />
10294
</Docs>

src/routes/docs/references/[version]/[platform]/[service]/+layout.svelte

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/scss/7-components/_main-header.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@
4444
&-link { color:hsl(var(--color-neutral-0) / 0.64); }
4545
}
4646

47-
&.is-transparent { background-color:transparent; -webkit-backdrop-filter:blur(pxToRem(10)); backdrop-filter:blur(pxToRem(10)); }
47+
&.is-transparent {
48+
[data-js-enabled] & {
49+
background-color: transparent; -webkit-backdrop-filter:blur(pxToRem(10)); backdrop-filter:blur(pxToRem(10));
50+
}
51+
}
4852

4953
#{$theme-dark} &,
5054
&#{$theme-dark} {

src/scss/7-components/_top-banner.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@
66
background: linear-gradient(94deg, rgba(253, 54, 110, 0.00) 0%, rgba(253, 54, 110, 0.50) 50.82%, rgba(253, 54, 110, 0.00) 100%);
77
&-content { line-height:pxToRem(20); transition:var(--transition); }
88
&-button { position:absolute; inset-inline-end:pxToRem(12); }
9+
10+
[data-banner-hidden] & {
11+
display: none;
12+
}
913
}

0 commit comments

Comments
 (0)