This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
forked from HHS/simpler-grants-gov
-
Notifications
You must be signed in to change notification settings - Fork 0
[Issue #134] Renable static rendering #85
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { NextIntlClientProvider } from "next-intl"; | ||
import { getMessages, unstable_setRequestLocale } from "next-intl/server"; | ||
|
||
import { GoogleAnalytics } from "@next/third-parties/google"; | ||
import { PUBLIC_ENV } from "src/constants/environments"; | ||
|
||
import Layout from "src/components/Layout"; | ||
|
||
/** | ||
* Root layout component, wraps all pages. | ||
* @see https://nextjs.org/docs/app/api-reference/file-conventions/layout | ||
*/ | ||
import { Metadata } from "next"; | ||
|
||
export const metadata: Metadata = { | ||
icons: [`${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/img/favicon.ico`], | ||
}; | ||
|
||
interface Props { | ||
children: React.ReactNode; | ||
params: { | ||
locale: string; | ||
}; | ||
} | ||
|
||
const locales = ["en", "es"]; | ||
|
||
export function generateStaticParams() { | ||
return locales.map((locale) => ({ locale })); | ||
} | ||
|
||
export default async function LocaleLayout({ children, params }: Props) { | ||
const { locale } = params; | ||
|
||
// Enable static rendering | ||
unstable_setRequestLocale(locale); | ||
|
||
// Providing all messages to the client | ||
// side is the easiest way to get started | ||
const messages = await getMessages(); | ||
|
||
return ( | ||
<html lang={locale}> | ||
<head> | ||
<GoogleAnalytics gaId={PUBLIC_ENV.GOOGLE_ANALYTICS_ID} /> | ||
</head> | ||
<body> | ||
<NextIntlClientProvider messages={messages}> | ||
<Layout locale={locale}>{children}</Layout> | ||
</NextIntlClientProvider> | ||
</body> | ||
</html> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,10 @@ | ||
import "src/styles/styles.scss"; | ||
import { GoogleAnalytics } from "@next/third-parties/google"; | ||
import { PUBLIC_ENV } from "src/constants/environments"; | ||
import { ReactNode } from "react"; | ||
|
||
import Layout from "src/components/Layout"; | ||
import { unstable_setRequestLocale } from "next-intl/server"; | ||
/** | ||
* Root layout component, wraps all pages. | ||
* @see https://nextjs.org/docs/app/api-reference/file-conventions/layout | ||
*/ | ||
import { Metadata } from "next"; | ||
|
||
export const metadata: Metadata = { | ||
icons: [`${process.env.NEXT_PUBLIC_BASE_PATH ?? ""}/img/favicon.ico`], | ||
type Props = { | ||
children: ReactNode; | ||
}; | ||
|
||
interface LayoutProps { | ||
children: React.ReactNode; | ||
params: { | ||
locale: string; | ||
}; | ||
} | ||
|
||
export default function RootLayout({ children, params }: LayoutProps) { | ||
// Hardcoded until the [locale] routing is enabled. | ||
const locale = params.locale ? params.locale : "en"; | ||
// TODO: Remove when https://github.com/amannn/next-intl/issues/663 lands. | ||
unstable_setRequestLocale(locale); | ||
|
||
return ( | ||
<html lang={locale}> | ||
<head> | ||
<GoogleAnalytics gaId={PUBLIC_ENV.GOOGLE_ANALYTICS_ID} /> | ||
</head> | ||
<body> | ||
{/* Separate layout component for the inner-body UI elements since Storybook | ||
and tests trip over the fact that this file renders an <html> tag */} | ||
|
||
{/* TODO: Add locale="english" prop when ready for i18n */} | ||
<Layout locale={locale}>{children}</Layout> | ||
</body> | ||
</html> | ||
); | ||
export default function RootLayout({ children }: Props) { | ||
return children; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a code comment here that
unstable_setRequestLocale
is a temporary API that next-intl aims to remove it in the future?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…and that, per their docs, you must be "cautious to apply it in all relevant places"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we make a ticket for dealing with this in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name
unstable_
is a common convention and speaks for itself, and this is used in every page, so would opt not to comment in the code. I'll create a ticket to remove it. It could be a while based on amannn/next-intl#663