Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Move Pages to App Router #7

Merged
merged 26 commits into from
May 23, 2024
Merged

Move Pages to App Router #7

merged 26 commits into from
May 23, 2024

Conversation

acouch
Copy link
Member

@acouch acouch commented May 15, 2024

Summary

Fixes #6

Time to review: 60 mins

Changes proposed

Move pages from page to app router:

  1. Move all pages to [locale] folder
  2. Add generateMetata() function and next-intl getTranslations() implementation
    • @rylew1 commented we could remove this from each page. To do that we could use prop arguments and update the based on the param. There is also more we can do with the metadata to properly add app links and twitter cards. TODO: create ticket
  3. Replace i18n's useTranslation with next-intl's useTranslations
  4. Remove hard-coded strings that were present b/c we were still b/w i18next and next-intl

Changes

Misc

  1. Delete hello api
    • This was left from the project creation
  2. Add USWDS icon component
    • as noted in a slack discussion, when trying to access one of the icons using <Icon.Search/> next errors: You cannot dot into a client module from a server component. You can only pass the imported name through. I'm not sure why it thinks the Icon component is a client module. Dan A. suggests trussworks should re-export as named exports. I tried importing the SVGs directly from the trussworks library but svgr requires a custom webpack config which is a road I didn't want to go down and react svg through an error in the app router 😥 .
    • I implemented @sawyerh 's suggestion, which did not work initially b/c next reported the USWDS icon was corrupt, which was fixed by adding a viewBox to the svg element 😮‍💨 .

Layout and component updates

Remaining next-intl config and removal of

Next Steps

  • Explore ensuring that the pages are statically rendered
  • Update generateMedata implementation
  • Remove <PageSEO/> component
  • Improve test coverage

Context for reviewers

  1. I would have liked to break this up into more PRs, however the individual page tests failed if the [locale] folder was not implemented, and when the [locale] folder was implemented, it broke the routing for the non-app pages
  2. There is still clean-up to do, but this gets us off the page router
  3. I left the newsletter API in the pages router since we can't test that ATM.

Copy link

github-actions bot commented May 15, 2024

Coverage report for ./frontend

St.
Category Percentage Covered / Total
🟢 Statements
83.23% (-0.94% 🔻)
844/1014
🟡 Branches
68.31% (+3.19% 🔼)
222/325
🟡 Functions
75.46% (-0.11% 🔻)
163/216
🟢 Lines
82.78% (-1.44% 🔻)
793/958
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🔴
... / actions.ts
57.14% 100% 0% 57.14%
🟡
... / page.tsx
75% 100% 50% 75%
🟢
... / NewsletterForm.tsx
93.75% 78.57% 87.5% 93.62%
🔴
... / page.tsx
57.14% 100% 50% 57.14%
🟢
... / FeatureFlagsTable.tsx
100% 100% 100% 100%
🟢
... / USWDSIcon.tsx
100% 100% 100% 100%
🟡
... / page.tsx
69.23% 100% 50% 69.23%
🟢
... / IndexGoalContent.tsx
100% 100% 100% 100%
🟢
... / ProcessAndResearchContent.tsx
100% 100% 100% 100%
🟡
... / page.tsx
73.33% 100% 50% 73.33%
🟢
... / ProcessIntro.tsx
100% 100% 100% 100%
🟢
... / ProcessInvolved.tsx
100% 100% 100% 100%
🟢
... / ProcessMilestones.tsx
94.74% 66.67% 100% 94.44%
🟡
... / page.tsx
76.47% 100% 50% 76.47%
🟢
... / ResearchIntro.tsx
100% 100% 100% 100%
🟢
... / ResearchArchetypes.tsx
100% 100% 100% 100%
🟢
... / ResearchImpact.tsx
100% 100% 100% 100%
🟢
... / ResearchMethodology.tsx
100% 100% 100% 100%
🟢
... / ResearchThemes.tsx
100% 100% 100% 100%
🟢
... / FundingContent.tsx
100% 100% 100% 100%
🟡
... / page.tsx
71.43% 100% 50% 71.43%
🟡
... / page.tsx
71.43% 100% 50% 71.43%

Test suite run success

158 tests passing in 54 suites.

Report generated by 🧪jest coverage report action from c40b27b

@@ -0,0 +1,51 @@
import { Grid } from "@trussworks/react-uswds";
import { useTranslations, useMessages } from "next-intl";
import ContentLayout from "src/components/ContentLayout";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should process have its own folder under the component folder?

@acouch acouch changed the title Add process page Move Pages to App Router May 21, 2024
@rylew1
Copy link
Collaborator

rylew1 commented May 21, 2024

we probably want these changes to run against the updated e2e search.spec file

@acouch acouch force-pushed the acouch/issue-6-move-pages-app branch from d2012e4 to 39f115d Compare May 22, 2024 21:33
@acouch acouch force-pushed the acouch/issue-6-move-pages-app branch from 39f115d to fab1ffa Compare May 23, 2024 14:02
@acouch acouch marked this pull request as ready for review May 23, 2024 14:02
@acouch acouch requested a review from andycochran as a code owner May 23, 2024 14:02
@acouch acouch merged commit 2572fe0 into main May 23, 2024
11 checks passed
@acouch acouch deleted the acouch/issue-6-move-pages-app branch May 23, 2024 20:26
acouch added a commit that referenced this pull request Sep 18, 2024
Fixes #6

1. Move all pages to
[`[locale]`](https://next-intl-docs.vercel.app/docs/getting-started/app-router/with-i18n-routing#getting-started)
folder
2. Add
[`generateMetata()`](https://nextjs.org/docs/app/api-reference/functions/generate-metadata#generatemetadata-function)
function and [next-intl
`getTranslations()`](https://next-intl-docs.vercel.app/docs/environments/metadata-route-handlers#metadata-api)
implementation
* @rylew1 commented we could remove this from each page. To do that we
could use [prop
arguments](https://nextjs.org/docs/app/api-reference/functions/generate-metadata#with-segment-props)
and update the based on the param. There is also more we can do with the
metadata to properly add [app links and twitter
cards](https://nextjs.org/docs/app/api-reference/functions/generate-metadata#applinks).
TODO: create ticket
4. Replace i18n's `useTranslation` with next-intl's `useTranslations`
5. Remove hard-coded strings that were present b/c we were still b/w
i18next and next-intl

* [Move process page to
app](32ba4ee)

* [Move research page to
app](5b5ad1a)

* [Move health page to
app](a3e6255)

* [Move feature flag page to
app](395baed)
* [Move search page to app
router](1e261e3)
* [Move newsletter pages to app
router](b509ef8)
* [Move home page to app
router](de1be98)
* [Move home page to app
router](74077ae)
* [Move 404 page to app
router](ccbc956)

1. [Delete hello
api](5bad6ea)
     * This was left from the project creation
2. [Add USWDS icon
component](0120c7b)
* as noted in a slack discussion, when trying to access [one of the
icons](https://github.com/trussworks/react-uswds/blob/main/src/components/Icon/Icons.ts)
using `<Icon.Search/>` next errors: `You cannot dot into a client module
from a server component. You can only pass the imported name through`.
I'm not sure why it thinks the Icon component is a client module. [Dan
A.
suggests](vercel/next.js#51593 (comment))
trussworks should re-export as named exports. I tried importing the SVGs
directly from the trussworks library but [svgr requires a custom webpack
config](https://react-svgr.com/docs/next/) which is a road I didn't want
to go down and [react svg](https://www.npmjs.com/package/react-svg)
through an error in the app router 😥 .
* I implemented @sawyerh 's
[suggestion](0120c7b#diff-dadb35bd2f3f61f2c179f033cd0a2874fc343974236f2fb8613664703c751429),
which did not work initially b/c next reported the USWDS icon was
corrupt, which was fixed by adding a `viewBox` to the svg element 😮‍💨 .
* [Remove unused
WtGIContent](75490f7)

* [Move layout and update for app
router](af112fd)

* [Update global components for the app
router](40119e6)

* [Move i18n strings for app
router](eb3c07c)

* [Adds next-intl config and removes
i18n](c546571)

* [Update tests for app
router](3b9b193)

* [Removes i18next and next-i18n
packages](9d2e08a)

* [Update storybook settings for app
router](39f115d)
acouch added a commit that referenced this pull request Sep 18, 2024
Fixes #6

1. Move all pages to
[`[locale]`](https://next-intl-docs.vercel.app/docs/getting-started/app-router/with-i18n-routing#getting-started)
folder
2. Add
[`generateMetata()`](https://nextjs.org/docs/app/api-reference/functions/generate-metadata#generatemetadata-function)
function and [next-intl
`getTranslations()`](https://next-intl-docs.vercel.app/docs/environments/metadata-route-handlers#metadata-api)
implementation
* @rylew1 commented we could remove this from each page. To do that we
could use [prop
arguments](https://nextjs.org/docs/app/api-reference/functions/generate-metadata#with-segment-props)
and update the based on the param. There is also more we can do with the
metadata to properly add [app links and twitter
cards](https://nextjs.org/docs/app/api-reference/functions/generate-metadata#applinks).
TODO: create ticket
4. Replace i18n's `useTranslation` with next-intl's `useTranslations`
5. Remove hard-coded strings that were present b/c we were still b/w
i18next and next-intl

* [Move process page to
app](32ba4ee)

* [Move research page to
app](5b5ad1a)

* [Move health page to
app](a3e6255)

* [Move feature flag page to
app](395baed)
* [Move search page to app
router](1e261e3)
* [Move newsletter pages to app
router](b509ef8)
* [Move home page to app
router](de1be98)
* [Move home page to app
router](74077ae)
* [Move 404 page to app
router](ccbc956)

1. [Delete hello
api](5bad6ea)
     * This was left from the project creation
2. [Add USWDS icon
component](0120c7b)
* as noted in a slack discussion, when trying to access [one of the
icons](https://github.com/trussworks/react-uswds/blob/main/src/components/Icon/Icons.ts)
using `<Icon.Search/>` next errors: `You cannot dot into a client module
from a server component. You can only pass the imported name through`.
I'm not sure why it thinks the Icon component is a client module. [Dan
A.
suggests](vercel/next.js#51593 (comment))
trussworks should re-export as named exports. I tried importing the SVGs
directly from the trussworks library but [svgr requires a custom webpack
config](https://react-svgr.com/docs/next/) which is a road I didn't want
to go down and [react svg](https://www.npmjs.com/package/react-svg)
through an error in the app router 😥 .
* I implemented @sawyerh 's
[suggestion](0120c7b#diff-dadb35bd2f3f61f2c179f033cd0a2874fc343974236f2fb8613664703c751429),
which did not work initially b/c next reported the USWDS icon was
corrupt, which was fixed by adding a `viewBox` to the svg element 😮‍💨 .
* [Remove unused
WtGIContent](75490f7)

* [Move layout and update for app
router](af112fd)

* [Update global components for the app
router](40119e6)

* [Move i18n strings for app
router](eb3c07c)

* [Adds next-intl config and removes
i18n](c546571)

* [Update tests for app
router](3b9b193)

* [Removes i18next and next-i18n
packages](9d2e08a)

* [Update storybook settings for app
router](39f115d)
acouch added a commit to HHS/simpler-grants-gov that referenced this pull request Sep 18, 2024
Fixes #6

1. Move all pages to
[`[locale]`](https://next-intl-docs.vercel.app/docs/getting-started/app-router/with-i18n-routing#getting-started)
folder
2. Add
[`generateMetata()`](https://nextjs.org/docs/app/api-reference/functions/generate-metadata#generatemetadata-function)
function and [next-intl
`getTranslations()`](https://next-intl-docs.vercel.app/docs/environments/metadata-route-handlers#metadata-api)
implementation
* @rylew1 commented we could remove this from each page. To do that we
could use [prop
arguments](https://nextjs.org/docs/app/api-reference/functions/generate-metadata#with-segment-props)
and update the based on the param. There is also more we can do with the
metadata to properly add [app links and twitter
cards](https://nextjs.org/docs/app/api-reference/functions/generate-metadata#applinks).
TODO: create ticket
4. Replace i18n's `useTranslation` with next-intl's `useTranslations`
5. Remove hard-coded strings that were present b/c we were still b/w
i18next and next-intl

* [Move process page to
app](navapbc@32ba4ee)

* [Move research page to
app](navapbc@5b5ad1a)

* [Move health page to
app](navapbc@a3e6255)

* [Move feature flag page to
app](navapbc@395baed)
* [Move search page to app
router](navapbc@1e261e3)
* [Move newsletter pages to app
router](navapbc@b509ef8)
* [Move home page to app
router](navapbc@de1be98)
* [Move home page to app
router](navapbc@74077ae)
* [Move 404 page to app
router](navapbc@ccbc956)

1. [Delete hello
api](navapbc@5bad6ea)
     * This was left from the project creation
2. [Add USWDS icon
component](navapbc@0120c7b)
* as noted in a slack discussion, when trying to access [one of the
icons](https://github.com/trussworks/react-uswds/blob/main/src/components/Icon/Icons.ts)
using `<Icon.Search/>` next errors: `You cannot dot into a client module
from a server component. You can only pass the imported name through`.
I'm not sure why it thinks the Icon component is a client module. [Dan
A.
suggests](vercel/next.js#51593 (comment))
trussworks should re-export as named exports. I tried importing the SVGs
directly from the trussworks library but [svgr requires a custom webpack
config](https://react-svgr.com/docs/next/) which is a road I didn't want
to go down and [react svg](https://www.npmjs.com/package/react-svg)
through an error in the app router 😥 .
* I implemented @sawyerh 's
[suggestion](navapbc@0120c7b#diff-dadb35bd2f3f61f2c179f033cd0a2874fc343974236f2fb8613664703c751429),
which did not work initially b/c next reported the USWDS icon was
corrupt, which was fixed by adding a `viewBox` to the svg element 😮‍💨 .
* [Remove unused
WtGIContent](navapbc@75490f7)

* [Move layout and update for app
router](navapbc@af112fd)

* [Update global components for the app
router](navapbc@40119e6)

* [Move i18n strings for app
router](navapbc@eb3c07c)

* [Adds next-intl config and removes
i18n](navapbc@c546571)

* [Update tests for app
router](navapbc@3b9b193)

* [Removes i18next and next-i18n
packages](navapbc@9d2e08a)

* [Update storybook settings for app
router](navapbc@39f115d)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Task]: Move pages to the app router
2 participants