Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FOUC #323

Merged
merged 11 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
}
}
}

document.body.dataset.jsEnabled = '';
</script>
<div style="display: contents">%sveltekit.body%</div>
</body>
Expand Down
21 changes: 11 additions & 10 deletions src/lib/layouts/Main.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

<script lang="ts">
import { browser } from '$app/environment';
import { page } from '$app/stores';
import { MobileNav } from '$lib/components';
import { isVisible } from '$lib/utils/isVisible';
import { createScrollInfo } from '$lib/utils/scroll';
import { addEventListener } from '@melt-ui/svelte/internal/helpers';
import { onMount } from 'svelte';
import { slide } from 'svelte/transition';
import { persisted } from '$lib/utils/persisted';

let theme: 'light' | 'dark' | null = 'dark';

Expand Down Expand Up @@ -112,11 +112,13 @@
return $scrollInfo.deltaDirChange < 200;
})();

const BANNER_KEY = 'discord-banner-00'; // Change this key whenever you want to show the banner again for all users
let showTopBanner = persisted(BANNER_KEY, {
defaultValue: true,
validate: (value): value is boolean => typeof value === 'boolean'
});
let showTopBanner = $page.data.showBanner;
const hideTopBanner = () => {
showTopBanner = false;
fetch('/api/banner', {
method: 'POST'
});
};
</script>

<div class="u-position-relative">
Expand Down Expand Up @@ -163,11 +165,10 @@
</div>
</section>
<header
class="aw-main-header is-special-padding theme-{resolvedTheme}"
class:is-transparent={browser}
class="aw-main-header is-special-padding theme-{resolvedTheme} is-transparent"
class:is-hidden={$isHeaderHidden}
>
{#if $showTopBanner}
{#if showTopBanner}
<div class="aw-top-banner" transition:slide={{ duration: 250 }}>
<div class="aw-top-banner-content aw-u-color-text-primary">
<a href="/discord" target="_blank" rel="noopener noreferrer">
Expand All @@ -179,7 +180,7 @@
<button
class="aw-top-banner-button"
aria-label="close discord message"
on:click={() => ($showTopBanner = false)}
on:click={hideTopBanner}
>
<span class="aw-icon-close" aria-hidden="true" />
</button>
Expand Down
6 changes: 6 additions & 0 deletions src/routes/+layout.server.ts
TorstenDittmann marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
import { BANNER_KEY } from './api/banner/constants.js';

export const prerender = true;

export const load = async ({ cookies }) => {
return { showBanner: cookies.get(BANNER_KEY) !== 'true' };
};
TorstenDittmann marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 11 additions & 0 deletions src/routes/api/banner/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { BANNER_KEY } from './constants.js';

export const POST = ({ cookies }) => {
cookies.set(BANNER_KEY, 'true', {
path: '/'
});

return new Response(null, {
status: 200
});
};
1 change: 1 addition & 0 deletions src/routes/api/banner/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const BANNER_KEY = 'discord-banner-00'; // Change key to force banner to show again
16 changes: 4 additions & 12 deletions src/routes/docs/references/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
<script lang="ts" context="module">
export function getReferencesContext() {
return getContext<Writable<boolean>>('references-expandable');
}
</script>

<script lang="ts">
import { page } from '$app/stores';
import Docs from '$lib/layouts/Docs.svelte';
import { preferredPlatform, preferredVersion } from '$lib/utils/references';
import { writable, type Writable } from 'svelte/store';
import { getContext, setContext } from 'svelte';
import Sidebar, { type NavParent, type NavTree } from '$lib/layouts/Sidebar.svelte';
import { preferredPlatform, preferredVersion } from '$lib/utils/references';
const expandable = setContext('references-expandable', writable(false));
$: expandable = !!$page.url.pathname.match(/\/docs\/references\/.*?\/.*?\/.*?\/?/);
$: prefix = `/docs/references/${$preferredVersion ?? $page.params?.version ?? 'cloud'}/${
$preferredPlatform ?? $page.params?.platform ?? 'client-web'
Expand Down Expand Up @@ -96,7 +88,7 @@
};
</script>

<Docs variant={$expandable ? 'expanded' : 'two-side-navs'} isReferences={$expandable}>
<Sidebar {navigation} expandable={$expandable} {parent} />
<Docs variant={expandable ? 'expanded' : 'two-side-navs'} isReferences={expandable}>
<Sidebar {navigation} {expandable} {parent} />
<slot />
</Docs>

This file was deleted.

6 changes: 5 additions & 1 deletion src/scss/7-components/_main-header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@
&-link { color:hsl(var(--color-neutral-0) / 0.64); }
}

&.is-transparent { background-color:transparent; -webkit-backdrop-filter:blur(pxToRem(10)); backdrop-filter:blur(pxToRem(10)); }
&.is-transparent {
[data-js-enabled] & {
background-color: transparent; -webkit-backdrop-filter:blur(pxToRem(10)); backdrop-filter:blur(pxToRem(10));
}
}

#{$theme-dark} &,
&#{$theme-dark} {
Expand Down
5 changes: 3 additions & 2 deletions svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ function absoulute(path) {
return join(dirname(fileURLToPath(import.meta.url)), path);
}

const isVercel = process.env.VERCEL === '1';
// const isVercel = process.env.VERCEL === '1';
const isVercel = true;
TorstenDittmann marked this conversation as resolved.
Show resolved Hide resolved

const adapter = isVercel ? staticAdapter() : nodeAdapter();
const adapter = isVercel ? staticAdapter({ strict: false, pages: 'public' }) : nodeAdapter();

/** @type {import('@sveltejs/kit').Config}*/
const config = {
Expand Down