From ac726d1989a1b2cbcaceb128b18496e8f4e21ddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcholas=20Oliveira?= Date: Thu, 25 Jul 2024 21:37:24 -0300 Subject: [PATCH 1/5] feat: static rendering --- package-lock.json | 211 +++++++++--------- packages/next/src/middlewares/appMidleware.ts | 4 +- packages/next/src/rsc/config.ts | 21 +- .../next/src/rsc/data/queries/prepareQuery.ts | 2 +- .../src/app/(single)/[...path]/page.tsx | 29 ++- .../src/app/api/preview/route.ts | 2 + .../src/app/api/revalidate/route.ts | 2 + projects/wp-nextjs-app/src/app/page.tsx | 4 +- .../app/[lang]/(single)/[...path]/page.tsx | 31 ++- .../src/app/[lang]/layout.tsx | 5 + 10 files changed, 188 insertions(+), 123 deletions(-) diff --git a/package-lock.json b/package-lock.json index b0e0c5a5a..1258b3857 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21574,6 +21574,7 @@ } }, "projects/wp-polylang-nextjs-app": { + "name": "@10up/wp-polylang-nextjs-app", "version": "0.1.0", "dependencies": { "@headstartwp/core": "^1.4.3", @@ -21597,6 +21598,66 @@ "resolved": "https://registry.npmjs.org/@next/env/-/env-14.2.3.tgz", "integrity": "sha512-W7fd7IbkfmeeY2gXrzJYDx8D2lWKbVoTIj1o1ScPHNzvp30s1AuoEFSdr39bC5sjxJaxTtq3OTCZboNp0lNWHA==" }, + "projects/wp-polylang-nextjs-app/node_modules/@next/swc-darwin-arm64": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.3.tgz", + "integrity": "sha512-3pEYo/RaGqPP0YzwnlmPN2puaF2WMLM3apt5jLW2fFdXD9+pqcoTzRk+iZsf8ta7+quAe4Q6Ms0nR0SFGFdS1A==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "projects/wp-polylang-nextjs-app/node_modules/@next/swc-darwin-x64": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.3.tgz", + "integrity": "sha512-6adp7waE6P1TYFSXpY366xwsOnEXM+y1kgRpjSRVI2CBDOcbRjsJ67Z6EgKIqWIue52d2q/Mx8g9MszARj8IEA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "projects/wp-polylang-nextjs-app/node_modules/@next/swc-linux-arm64-gnu": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.3.tgz", + "integrity": "sha512-cuzCE/1G0ZSnTAHJPUT1rPgQx1w5tzSX7POXSLaS7w2nIUJUD+e25QoXD/hMfxbsT9rslEXugWypJMILBj/QsA==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "projects/wp-polylang-nextjs-app/node_modules/@next/swc-linux-arm64-musl": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.3.tgz", + "integrity": "sha512-0D4/oMM2Y9Ta3nGuCcQN8jjJjmDPYpHX9OJzqk42NZGJocU2MqhBq5tWkJrUQOQY9N+In9xOdymzapM09GeiZw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, "projects/wp-polylang-nextjs-app/node_modules/@next/swc-linux-x64-gnu": { "version": "14.2.3", "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.3.tgz", @@ -21627,6 +21688,51 @@ "node": ">= 10" } }, + "projects/wp-polylang-nextjs-app/node_modules/@next/swc-win32-arm64-msvc": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.3.tgz", + "integrity": "sha512-AEHIw/dhAMLNFJFJIJIyOFDzrzI5bAjI9J26gbO5xhAKHYTZ9Or04BesFPXiAYXDNdrwTP2dQceYA4dL1geu8A==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "projects/wp-polylang-nextjs-app/node_modules/@next/swc-win32-ia32-msvc": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.3.tgz", + "integrity": "sha512-vga40n1q6aYb0CLrM+eEmisfKCR45ixQYXuBXxOOmmoV8sYST9k7E3US32FsY+CkkF7NtzdcebiFT4CHuMSyZw==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "projects/wp-polylang-nextjs-app/node_modules/@next/swc-win32-x64-msvc": { + "version": "14.2.3", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.3.tgz", + "integrity": "sha512-Q1/zm43RWynxrO7lW4ehciQVj+5ePBhOK+/K2P7pLFX3JaJ/IZVC69SHidrmZSOkqz7ECIOhhy7XhAFG4JYyHA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, "projects/wp-polylang-nextjs-app/node_modules/@types/node": { "version": "20.14.12", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.12.tgz", @@ -21708,111 +21814,6 @@ "engines": { "node": ">=16.0.0" } - }, - "projects/wp-polylang-nextjs-app/node_modules/@next/swc-darwin-arm64": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.3.tgz", - "integrity": "sha512-3pEYo/RaGqPP0YzwnlmPN2puaF2WMLM3apt5jLW2fFdXD9+pqcoTzRk+iZsf8ta7+quAe4Q6Ms0nR0SFGFdS1A==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">= 10" - } - }, - "projects/wp-polylang-nextjs-app/node_modules/@next/swc-darwin-x64": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.3.tgz", - "integrity": "sha512-6adp7waE6P1TYFSXpY366xwsOnEXM+y1kgRpjSRVI2CBDOcbRjsJ67Z6EgKIqWIue52d2q/Mx8g9MszARj8IEA==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">= 10" - } - }, - "projects/wp-polylang-nextjs-app/node_modules/@next/swc-linux-arm64-gnu": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.3.tgz", - "integrity": "sha512-cuzCE/1G0ZSnTAHJPUT1rPgQx1w5tzSX7POXSLaS7w2nIUJUD+e25QoXD/hMfxbsT9rslEXugWypJMILBj/QsA==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "projects/wp-polylang-nextjs-app/node_modules/@next/swc-linux-arm64-musl": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.3.tgz", - "integrity": "sha512-0D4/oMM2Y9Ta3nGuCcQN8jjJjmDPYpHX9OJzqk42NZGJocU2MqhBq5tWkJrUQOQY9N+In9xOdymzapM09GeiZw==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">= 10" - } - }, - "projects/wp-polylang-nextjs-app/node_modules/@next/swc-win32-arm64-msvc": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.3.tgz", - "integrity": "sha512-AEHIw/dhAMLNFJFJIJIyOFDzrzI5bAjI9J26gbO5xhAKHYTZ9Or04BesFPXiAYXDNdrwTP2dQceYA4dL1geu8A==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10" - } - }, - "projects/wp-polylang-nextjs-app/node_modules/@next/swc-win32-ia32-msvc": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.3.tgz", - "integrity": "sha512-vga40n1q6aYb0CLrM+eEmisfKCR45ixQYXuBXxOOmmoV8sYST9k7E3US32FsY+CkkF7NtzdcebiFT4CHuMSyZw==", - "cpu": [ - "ia32" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10" - } - }, - "projects/wp-polylang-nextjs-app/node_modules/@next/swc-win32-x64-msvc": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.3.tgz", - "integrity": "sha512-Q1/zm43RWynxrO7lW4ehciQVj+5ePBhOK+/K2P7pLFX3JaJ/IZVC69SHidrmZSOkqz7ECIOhhy7XhAFG4JYyHA==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">= 10" - } } } } diff --git a/packages/next/src/middlewares/appMidleware.ts b/packages/next/src/middlewares/appMidleware.ts index df0b0e3d2..6c6845ef3 100644 --- a/packages/next/src/middlewares/appMidleware.ts +++ b/packages/next/src/middlewares/appMidleware.ts @@ -99,7 +99,7 @@ export async function AppMiddleware( const { pathname } = req.nextUrl; if (isStaticAssetRequest(req) || isInternalRequest(req)) { - return response; + return undefined; } const isPotentiallyMultisite = hasMultisiteConfig(); @@ -150,7 +150,7 @@ export async function AppMiddleware( } let shouldRedirect = false; - + console.log('locale', locale); if (locale && options.appRouter) { const { supportedLocales } = getAppRouterSupportedLocales(); diff --git a/packages/next/src/rsc/config.ts b/packages/next/src/rsc/config.ts index e982bb4eb..51f23fbbc 100644 --- a/packages/next/src/rsc/config.ts +++ b/packages/next/src/rsc/config.ts @@ -1,18 +1,15 @@ -import { getHeadstartWPConfig, getSiteByHost } from '@headstartwp/core'; -import { headers } from 'next/headers'; +import { HeadstartWPRoute } from './types'; +import { prepareQuery } from './data/queries/prepareQuery'; /** - * How to make this work in edge runtimes? + * Loads the right config based on route params + * + * @param routeParams The next.js route params + * + * @returns */ -export async function loadHeadstartWPConfig() { - const config = getHeadstartWPConfig(); - const headersList = headers(); - - const site = headersList.get('x-headstartwp-site'); - - if (site) { - return getSiteByHost(site); - } +export function loadHeadstartWPConfig(routeParams: HeadstartWPRoute['params']) { + const { config } = prepareQuery({ routeParams }); return config; } diff --git a/packages/next/src/rsc/data/queries/prepareQuery.ts b/packages/next/src/rsc/data/queries/prepareQuery.ts index 52e06ca75..7aaa933e5 100644 --- a/packages/next/src/rsc/data/queries/prepareQuery.ts +++ b/packages/next/src/rsc/data/queries/prepareQuery.ts @@ -54,7 +54,7 @@ export function prepareQuery

( const supportedLocales = rootConfig.i18n?.locales ?? []; if (!supportedLocales.includes(routeParams.lang)) { throw new FrameworkError( - 'Unsuported lang, make sure you add all desired locales to `config.i18n.locales`', + `Unsuported lang (${routeParams.lang}), make sure you add all desired locales to "config.i18n.locales"`, ); } params.lang = routeParams.lang; diff --git a/projects/wp-nextjs-app/src/app/(single)/[...path]/page.tsx b/projects/wp-nextjs-app/src/app/(single)/[...path]/page.tsx index d5825b644..da37bc487 100644 --- a/projects/wp-nextjs-app/src/app/(single)/[...path]/page.tsx +++ b/projects/wp-nextjs-app/src/app/(single)/[...path]/page.tsx @@ -1,8 +1,35 @@ import { HtmlDecoder } from '@headstartwp/core/react'; -import { HeadstartWPRoute, JSONLD, queryPost } from '@headstartwp/next/app'; +import { + HeadstartWPRoute, + JSONLD, + loadHeadstartWPConfig, + queryPost, + queryPosts, +} from '@headstartwp/next/app'; import { Metadata } from 'next'; +import { removeSourceUrl } from '@headstartwp/core'; import Blocks from '../../../components/Blocks'; +export async function generateStaticParams({ params }: HeadstartWPRoute) { + // loads the right config based on route params (this is needed over getHeadstartWP for sites using polylang integration or multisite) + const { sourceUrl = '', hostUrl = '/' } = loadHeadstartWPConfig(params); + + const { data } = await queryPosts({ + routeParams: params, + params: { postType: 'post' }, + }); + + return data.posts.map((post) => ({ + path: removeSourceUrl({ + backendUrl: sourceUrl, + link: post.link, + publicUrl: hostUrl, + }) + .substring(1) + .split('/'), + })); +} + async function query({ params }: HeadstartWPRoute) { return queryPost({ routeParams: params, diff --git a/projects/wp-nextjs-app/src/app/api/preview/route.ts b/projects/wp-nextjs-app/src/app/api/preview/route.ts index ce26916d5..9ec544fff 100644 --- a/projects/wp-nextjs-app/src/app/api/preview/route.ts +++ b/projects/wp-nextjs-app/src/app/api/preview/route.ts @@ -1,6 +1,8 @@ import { previewRouteHandler } from '@headstartwp/next/app'; import type { NextRequest } from 'next/server'; +export const dynamic = 'force-dynamic'; + export async function GET(request: NextRequest) { // @ts-expect-error return previewRouteHandler(request); diff --git a/projects/wp-nextjs-app/src/app/api/revalidate/route.ts b/projects/wp-nextjs-app/src/app/api/revalidate/route.ts index dc1dc3548..324e9b272 100644 --- a/projects/wp-nextjs-app/src/app/api/revalidate/route.ts +++ b/projects/wp-nextjs-app/src/app/api/revalidate/route.ts @@ -1,6 +1,8 @@ import { revalidateRouteHandler } from '@headstartwp/next/app'; import type { NextRequest } from 'next/server'; +export const dynamic = 'force-dynamic'; + export async function GET(request: NextRequest) { // @ts-expect-error return revalidateRouteHandler(request); diff --git a/projects/wp-nextjs-app/src/app/page.tsx b/projects/wp-nextjs-app/src/app/page.tsx index 82d865633..d34cb379f 100644 --- a/projects/wp-nextjs-app/src/app/page.tsx +++ b/projects/wp-nextjs-app/src/app/page.tsx @@ -8,7 +8,9 @@ async function query({ params }: HeadstartWPRoute) { params: { slug: 'sample-page', postType: 'page', - matchCurrentPath: false, + }, + options: { + cache: 'force-cache', }, }); } diff --git a/projects/wp-polylang-nextjs-app/src/app/[lang]/(single)/[...path]/page.tsx b/projects/wp-polylang-nextjs-app/src/app/[lang]/(single)/[...path]/page.tsx index cf7831f37..5a64d521f 100644 --- a/projects/wp-polylang-nextjs-app/src/app/[lang]/(single)/[...path]/page.tsx +++ b/projects/wp-polylang-nextjs-app/src/app/[lang]/(single)/[...path]/page.tsx @@ -1,5 +1,34 @@ +import { removeSourceUrl } from '@headstartwp/core'; import { BlocksRenderer, HtmlDecoder } from '@headstartwp/core/react'; -import { HeadstartWPRoute, queryPost } from '@headstartwp/next/app'; +import { + HeadstartWPRoute, + loadHeadstartWPConfig, + queryPost, + queryPosts, +} from '@headstartwp/next/app'; + +export async function generateStaticParams({ params }: HeadstartWPRoute) { + // loads the right config based on route params (this is needed over getHeadstartWP for sites using multisite) + const { sourceUrl = '', hostUrl = '/' } = loadHeadstartWPConfig(params); + + const { data } = await queryPosts({ + routeParams: params, + params: { postType: 'post' }, + options: { + throwIfNotFound: false, + }, + }); + + return data.posts.map((post) => ({ + path: removeSourceUrl({ + backendUrl: sourceUrl, + link: post.link, + publicUrl: hostUrl, + }) + .substring(1) + .split('/'), + })); +} const Single = async ({ params }: HeadstartWPRoute) => { const { data } = await queryPost({ diff --git a/projects/wp-polylang-nextjs-app/src/app/[lang]/layout.tsx b/projects/wp-polylang-nextjs-app/src/app/[lang]/layout.tsx index 0501c9c14..b31edd097 100644 --- a/projects/wp-polylang-nextjs-app/src/app/[lang]/layout.tsx +++ b/projects/wp-polylang-nextjs-app/src/app/[lang]/layout.tsx @@ -2,6 +2,11 @@ import { HeadstartWPLayout, PreviewIndicator, queryAppSettings } from '@headstar import { Menu, SettingsProvider, ThemeSettingsProvider } from '@headstartwp/core/react'; import { getHeadstartWPConfig } from '@headstartwp/core'; +export async function generateStaticParams() { + // pre-render en and es posts + return [{ lang: 'en' }, { lang: 'es' }]; +} + const RootLayout = async ({ children, params }: Readonly) => { const { menu, data } = await queryAppSettings({ menu: 'primary', routeParams: params }); From b034a44ca1dae5222e5398a5c0dcda9855260065 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcholas=20Oliveira?= Date: Thu, 25 Jul 2024 21:38:46 -0300 Subject: [PATCH 2/5] fix: add force dynamic to route handlers --- projects/wp-multisite-nextjs-app/src/app/api/preview/route.ts | 2 ++ .../wp-multisite-nextjs-app/src/app/api/revalidate/route.ts | 2 ++ projects/wp-polylang-nextjs-app/src/app/api/preview/route.ts | 2 ++ projects/wp-polylang-nextjs-app/src/app/api/revalidate/route.ts | 2 ++ 4 files changed, 8 insertions(+) diff --git a/projects/wp-multisite-nextjs-app/src/app/api/preview/route.ts b/projects/wp-multisite-nextjs-app/src/app/api/preview/route.ts index ce26916d5..9ec544fff 100644 --- a/projects/wp-multisite-nextjs-app/src/app/api/preview/route.ts +++ b/projects/wp-multisite-nextjs-app/src/app/api/preview/route.ts @@ -1,6 +1,8 @@ import { previewRouteHandler } from '@headstartwp/next/app'; import type { NextRequest } from 'next/server'; +export const dynamic = 'force-dynamic'; + export async function GET(request: NextRequest) { // @ts-expect-error return previewRouteHandler(request); diff --git a/projects/wp-multisite-nextjs-app/src/app/api/revalidate/route.ts b/projects/wp-multisite-nextjs-app/src/app/api/revalidate/route.ts index dc1dc3548..324e9b272 100644 --- a/projects/wp-multisite-nextjs-app/src/app/api/revalidate/route.ts +++ b/projects/wp-multisite-nextjs-app/src/app/api/revalidate/route.ts @@ -1,6 +1,8 @@ import { revalidateRouteHandler } from '@headstartwp/next/app'; import type { NextRequest } from 'next/server'; +export const dynamic = 'force-dynamic'; + export async function GET(request: NextRequest) { // @ts-expect-error return revalidateRouteHandler(request); diff --git a/projects/wp-polylang-nextjs-app/src/app/api/preview/route.ts b/projects/wp-polylang-nextjs-app/src/app/api/preview/route.ts index ce26916d5..9ec544fff 100644 --- a/projects/wp-polylang-nextjs-app/src/app/api/preview/route.ts +++ b/projects/wp-polylang-nextjs-app/src/app/api/preview/route.ts @@ -1,6 +1,8 @@ import { previewRouteHandler } from '@headstartwp/next/app'; import type { NextRequest } from 'next/server'; +export const dynamic = 'force-dynamic'; + export async function GET(request: NextRequest) { // @ts-expect-error return previewRouteHandler(request); diff --git a/projects/wp-polylang-nextjs-app/src/app/api/revalidate/route.ts b/projects/wp-polylang-nextjs-app/src/app/api/revalidate/route.ts index dc1dc3548..324e9b272 100644 --- a/projects/wp-polylang-nextjs-app/src/app/api/revalidate/route.ts +++ b/projects/wp-polylang-nextjs-app/src/app/api/revalidate/route.ts @@ -1,6 +1,8 @@ import { revalidateRouteHandler } from '@headstartwp/next/app'; import type { NextRequest } from 'next/server'; +export const dynamic = 'force-dynamic'; + export async function GET(request: NextRequest) { // @ts-expect-error return revalidateRouteHandler(request); From 8146c9db7ddc874ba54f0b43b289123060d72d91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcholas=20Andr=C3=A9?= Date: Fri, 26 Jul 2024 02:37:39 +0000 Subject: [PATCH 3/5] fix: tests --- packages/next/src/middlewares/appMidleware.ts | 2 +- packages/next/src/rsc/data/queries/__tests__/prepareQuery.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/next/src/middlewares/appMidleware.ts b/packages/next/src/middlewares/appMidleware.ts index 6c6845ef3..dbc69a1d1 100644 --- a/packages/next/src/middlewares/appMidleware.ts +++ b/packages/next/src/middlewares/appMidleware.ts @@ -99,7 +99,7 @@ export async function AppMiddleware( const { pathname } = req.nextUrl; if (isStaticAssetRequest(req) || isInternalRequest(req)) { - return undefined; + return response; } const isPotentiallyMultisite = hasMultisiteConfig(); diff --git a/packages/next/src/rsc/data/queries/__tests__/prepareQuery.ts b/packages/next/src/rsc/data/queries/__tests__/prepareQuery.ts index 33be62b3e..f7c379037 100644 --- a/packages/next/src/rsc/data/queries/__tests__/prepareQuery.ts +++ b/packages/next/src/rsc/data/queries/__tests__/prepareQuery.ts @@ -169,7 +169,7 @@ describe('prepareQuery with lang and polylang', () => { getHeadstartWPConfig(), ), ).toThrow( - 'Unsuported lang, make sure you add all desired locales to `config.i18n.locales`', + 'Unsuported lang (br), make sure you add all desired locales to "config.i18n.locales"', ); }); }); From ebc4af34bde1c1c7af9d03fd45f626494c576121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcholas=20Oliveira?= Date: Fri, 26 Jul 2024 15:00:51 -0300 Subject: [PATCH 4/5] chore: changeset --- .changeset/tall-peas-compete.md | 6 ++++++ .../src/app/{[site] => }/favicon.ico | Bin .../src/app/[lang]/(single)/[...path]/page.tsx | 3 ++- .../src/app/{[lang] => }/favicon.ico | Bin 4 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changeset/tall-peas-compete.md rename projects/wp-multisite-nextjs-app/src/app/{[site] => }/favicon.ico (100%) rename projects/wp-polylang-nextjs-app/src/app/{[lang] => }/favicon.ico (100%) diff --git a/.changeset/tall-peas-compete.md b/.changeset/tall-peas-compete.md new file mode 100644 index 000000000..7f7217bc0 --- /dev/null +++ b/.changeset/tall-peas-compete.md @@ -0,0 +1,6 @@ +--- +"@headstartwp/core": patch +"@headstartwp/next": patch +--- + +Introducing `loadHeadstartWpConfig()` diff --git a/projects/wp-multisite-nextjs-app/src/app/[site]/favicon.ico b/projects/wp-multisite-nextjs-app/src/app/favicon.ico similarity index 100% rename from projects/wp-multisite-nextjs-app/src/app/[site]/favicon.ico rename to projects/wp-multisite-nextjs-app/src/app/favicon.ico diff --git a/projects/wp-polylang-nextjs-app/src/app/[lang]/(single)/[...path]/page.tsx b/projects/wp-polylang-nextjs-app/src/app/[lang]/(single)/[...path]/page.tsx index 5a64d521f..27f40aa02 100644 --- a/projects/wp-polylang-nextjs-app/src/app/[lang]/(single)/[...path]/page.tsx +++ b/projects/wp-polylang-nextjs-app/src/app/[lang]/(single)/[...path]/page.tsx @@ -8,9 +8,10 @@ import { } from '@headstartwp/next/app'; export async function generateStaticParams({ params }: HeadstartWPRoute) { - // loads the right config based on route params (this is needed over getHeadstartWP for sites using multisite) + // loads the right config based on route params (this is needed over getHeadstartWPConfig() for sites using multisite) const { sourceUrl = '', hostUrl = '/' } = loadHeadstartWPConfig(params); + // do not throw if there aren't any posts const { data } = await queryPosts({ routeParams: params, params: { postType: 'post' }, diff --git a/projects/wp-polylang-nextjs-app/src/app/[lang]/favicon.ico b/projects/wp-polylang-nextjs-app/src/app/favicon.ico similarity index 100% rename from projects/wp-polylang-nextjs-app/src/app/[lang]/favicon.ico rename to projects/wp-polylang-nextjs-app/src/app/favicon.ico From fd0f6a36894619316f4373156197ca58411c5455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcholas=20Oliveira?= Date: Fri, 26 Jul 2024 15:06:42 -0300 Subject: [PATCH 5/5] chore: remove console.log --- packages/next/src/middlewares/appMidleware.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/src/middlewares/appMidleware.ts b/packages/next/src/middlewares/appMidleware.ts index dbc69a1d1..df0b0e3d2 100644 --- a/packages/next/src/middlewares/appMidleware.ts +++ b/packages/next/src/middlewares/appMidleware.ts @@ -150,7 +150,7 @@ export async function AppMiddleware( } let shouldRedirect = false; - console.log('locale', locale); + if (locale && options.appRouter) { const { supportedLocales } = getAppRouterSupportedLocales();