Skip to content

Commit

Permalink
await parent() in page load functions until client hooks init arrives s…
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-8 committed Sep 27, 2022
1 parent 16cde23 commit 37393f5
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/site/src/lib/components/shell/User.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import { browser } from '$app/environment';
$: if (browser && $userStore) {
userStoreInited = true; // so that page will properly reflect logged out status and not fall back to user loaded from cookies
// alternatively after logging out (and thus clearing user cookie), could run invalidate() which would cause $page.data.user to be null achieving the desired result
}
</script>

Expand Down
1 change: 1 addition & 0 deletions packages/site/src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const load: LayoutServerLoad = async ({ cookies, request }) => {

const chosenLocale = cookies.get('locale') || null;

// perhaps could still run in hooks.server.ts
await loadLocaleOnServer(chosenLocale, acceptedLanguage);

let user: IUser = null;
Expand Down
3 changes: 2 additions & 1 deletion packages/site/src/routes/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { orderBy, where } from 'firebase/firestore';
import type { IDictionary } from '@living-dictionaries/types';

import type { PageLoad } from './$types';
export const load: PageLoad = async () => {
export const load: PageLoad = async ({ parent }) => {
await parent();
try {
const publicDictionaries = await getCollection<IDictionary>('dictionaries', [
orderBy('name'),
Expand Down
3 changes: 2 additions & 1 deletion packages/site/src/routes/[dictionaryId]/about/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { getDocument } from 'sveltefirets';
import type { IAbout } from '@living-dictionaries/types';

import type { PageLoad } from './$types';
export const load: PageLoad = async ({ params }) => {
export const load: PageLoad = async ({ params, parent }) => {
await parent();
try {
const aboutDoc = await getDocument<IAbout>(`dictionaries/${params.dictionaryId}/info/about`);
if (aboutDoc && aboutDoc.about) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import type { IEntry } from '@living-dictionaries/types';
import { getDocument } from 'sveltefirets';

import type { PageLoad } from './$types';
export const load: PageLoad = async ({ params }) => {
export const load: PageLoad = async ({ params, parent }) => {
await parent();
try {
const entry = await getDocument<IEntry>(
`dictionaries/${params.dictionaryId}/words/${params.entryId}`
Expand Down
3 changes: 2 additions & 1 deletion packages/site/src/routes/[dictionaryId]/grammar/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { getDocument } from 'sveltefirets';
import type { IGrammar } from '@living-dictionaries/types';

import type { PageLoad } from './$types';
export const load: PageLoad = async ({ params }) => {
export const load: PageLoad = async ({ params, parent }) => {
await parent();
try {
const grammarDoc = await getDocument<IGrammar>(
`dictionaries/${params.dictionaryId}/info/grammar`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { PageLoad } from './$types';
export const load: PageLoad = async ({ params }) => {
export const load: PageLoad = async ({ params, parent }) => {
await parent();
return {
inviteId: params.inviteId,
};
Expand Down
3 changes: 2 additions & 1 deletion packages/site/src/routes/dictionaries/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { getCollection } from 'sveltefirets';
import { orderBy, where } from 'firebase/firestore';

import type { PageLoad } from './$types';
export const load: PageLoad = async () => {
export const load: PageLoad = async ({ parent }) => {
await parent();
try {
const publicDictionaries = await getCollection<IDictionary>('dictionaries', [
orderBy('name'),
Expand Down
3 changes: 2 additions & 1 deletion packages/site/src/routes/setlocale/[bcp]/+page.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { PageLoad } from './$types';
export const load: PageLoad = async ({ params }) => {
export const load: PageLoad = async ({ params, parent }) => {
await parent();
return { bcp: params.bcp };
};

0 comments on commit 37393f5

Please sign in to comment.