Skip to content

Commit

Permalink
fix: load data beforeRender for projectCount
Browse files Browse the repository at this point in the history
  • Loading branch information
NilsJacobsen committed Feb 27, 2024
1 parent 6f3670e commit 294bfa4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions inlang/source-code/website/src/pages/index/+Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import Personas from "./custom_section/Personas/index.jsx"
import LixSection from "./custom_section/Lix/index.jsx"
import Features from "./custom_section/Features.jsx"

export default function Page(props: { projectCount: number }) {
export default function Page() {
const projectCount = currentPageContext.data.projectCount
return (
<>
<Title>{m.inlang_global_title()}</Title>
Expand Down Expand Up @@ -46,7 +47,7 @@ export default function Page(props: { projectCount: number }) {
rel="canonical"
/>
<MarketplaceLayout>
<HeroSearch projectCount={props.projectCount} />
<HeroSearch projectCount={projectCount} />
<Features />
<Personas />
{/* <ExtendSection /> */}
Expand Down
3 changes: 2 additions & 1 deletion inlang/source-code/website/src/renderer/+onBeforeRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import type { LanguageTag } from "@inlang/sdk"
import { sourceLanguageTag, availableLanguageTags } from "#src/paraglide/runtime.js"
import type { PageContext } from "vike/types"

export default function onBeforeRoute(pageContext: PageContext) {
export default function onBeforeRoute(pageContext: PageContext, data?: { projectCount: string }) {
const { url: urlWithoutLanguageTag, languageTag } = i18nRouting(pageContext.urlOriginal)
return {
pageContext: {
languageTag,
urlOriginal: urlWithoutLanguageTag,
data,
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion inlang/source-code/website/src/renderer/+onRenderHtml.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { MetaProvider, renderTags } from "@solidjs/meta"
import { languageTag } from "#src/paraglide/runtime.js"

// See https://vike.dev/data-fetching
export const passToClient = ["pageProps", "routeParams", "languageTag"] as const
export const passToClient = ["pageProps", "routeParams", "languageTag", "data"] as const

export default async function onRenderHtml(pageContext: PageContextRenderer): Promise<unknown> {
//! TODO most likely cross request state pollution
Expand Down
2 changes: 2 additions & 0 deletions inlang/source-code/website/src/renderer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type PageContextRenderer<PageProps = Record<string, unknown>> =
pageProps: PageProps
languageTag: string
meta: any
data: any
}

/**
Expand Down Expand Up @@ -49,5 +50,6 @@ export type PageContext<PageProps = Record<string, unknown>> = Pick<
export type OnBeforeRender<PageProps> = (pageContext: PageContextRenderer) => Promise<{
pageContext: {
pageProps: PageProps
data: any
}
}>

0 comments on commit 294bfa4

Please sign in to comment.