diff --git a/packages/next/src/rsc/data/queries/__tests__/queryPost.ts b/packages/next/src/rsc/data/queries/__tests__/queryPost.ts index 5e37cded0..9eef8523c 100644 --- a/packages/next/src/rsc/data/queries/__tests__/queryPost.ts +++ b/packages/next/src/rsc/data/queries/__tests__/queryPost.ts @@ -14,7 +14,7 @@ describe('queryPosts', () => { expect(data.post.slug).toBe('modi-qui-dignissimos-sed-assumenda-sint-iusto'); }); - it.skip('issues not found', async () => { + it('issues not found', async () => { await expect( queryPost({ routeParams: { diff --git a/packages/next/src/rsc/data/queries/__tests__/queryPosts.ts b/packages/next/src/rsc/data/queries/__tests__/queryPosts.ts index 44c70f18c..e13a03276 100644 --- a/packages/next/src/rsc/data/queries/__tests__/queryPosts.ts +++ b/packages/next/src/rsc/data/queries/__tests__/queryPosts.ts @@ -1,6 +1,19 @@ +import { setHeadstartWPConfig } from '@headstartwp/core'; import { queryPosts } from '../queryPosts'; describe('queryPosts', () => { + beforeAll(() => { + setHeadstartWPConfig({ + useWordPressPlugin: true, + }); + }); + + afterAll(() => { + setHeadstartWPConfig({ + useWordPressPlugin: false, + }); + }); + it('fetches posts', async () => { const { data } = await queryPosts({ params: { @@ -10,4 +23,30 @@ describe('queryPosts', () => { expect(data.posts).toHaveLength(2); }); + + it('issues not found', async () => { + await expect( + queryPosts({ + routeParams: { + path: ['category', 'not-found-category'], + }, + }), + ).rejects.toThrow(); + }); + + it('does not issue not found if throwIfNotFound is false', async () => { + const { data } = await queryPosts({ + routeParams: { + path: ['not-found-category'], + }, + params: { + taxonomy: 'category', + }, + options: { + throwIfNotFound: false, + }, + }); + + expect(data.posts).toHaveLength(0); + }); }); diff --git a/packages/next/src/rsc/data/queries/queryAppSettings.ts b/packages/next/src/rsc/data/queries/queryAppSettings.ts index dd479da4e..8bac20621 100644 --- a/packages/next/src/rsc/data/queries/queryAppSettings.ts +++ b/packages/next/src/rsc/data/queries/queryAppSettings.ts @@ -15,7 +15,7 @@ export async function queryAppSettings< return result; } catch (error) { if (error instanceof Error) { - handleFetchError(error, config, query.path); + await handleFetchError(error, config, query.path); } throw error; } diff --git a/packages/next/src/rsc/data/queries/queryAuthorArchive.ts b/packages/next/src/rsc/data/queries/queryAuthorArchive.ts index d41b18d2c..73c3873f8 100644 --- a/packages/next/src/rsc/data/queries/queryAuthorArchive.ts +++ b/packages/next/src/rsc/data/queries/queryAuthorArchive.ts @@ -20,7 +20,7 @@ export async function queryAuthorArchive< return result; } catch (error) { if (error instanceof Error) { - handleFetchError(error, config, query.path); + await handleFetchError(error, config, query.path); } throw error; } diff --git a/packages/next/src/rsc/data/queries/queryPost.ts b/packages/next/src/rsc/data/queries/queryPost.ts index ec1994deb..40d9ac817 100644 --- a/packages/next/src/rsc/data/queries/queryPost.ts +++ b/packages/next/src/rsc/data/queries/queryPost.ts @@ -15,7 +15,7 @@ export async function queryPost< return result; } catch (error) { if (error instanceof Error) { - handleFetchError(error, config, query.path); + await handleFetchError(error, config, query.path); } throw error; } diff --git a/packages/next/src/rsc/data/queries/queryPostOrPosts.ts b/packages/next/src/rsc/data/queries/queryPostOrPosts.ts index b3c553dbc..1d64be8df 100644 --- a/packages/next/src/rsc/data/queries/queryPostOrPosts.ts +++ b/packages/next/src/rsc/data/queries/queryPostOrPosts.ts @@ -15,7 +15,7 @@ export async function queryPostOrPosts< return result; } catch (error) { if (error instanceof Error) { - handleFetchError(error, config, query.path); + await handleFetchError(error, config, query.path); } throw error; } diff --git a/packages/next/src/rsc/data/queries/queryPosts.ts b/packages/next/src/rsc/data/queries/queryPosts.ts index 330c33a4c..bae6f7c5a 100644 --- a/packages/next/src/rsc/data/queries/queryPosts.ts +++ b/packages/next/src/rsc/data/queries/queryPosts.ts @@ -15,7 +15,7 @@ export async function queryPosts< return result; } catch (error) { if (error instanceof Error) { - handleFetchError(error, config, query.path); + await handleFetchError(error, config, query.path); } throw error; } diff --git a/packages/next/src/rsc/data/queries/querySearch.ts b/packages/next/src/rsc/data/queries/querySearch.ts index cc1b55604..7357b5257 100644 --- a/packages/next/src/rsc/data/queries/querySearch.ts +++ b/packages/next/src/rsc/data/queries/querySearch.ts @@ -21,7 +21,7 @@ export async function querySearch< return result; } catch (error) { if (error instanceof Error) { - handleFetchError(error, config, query.path); + await handleFetchError(error, config, query.path); } throw error; } diff --git a/packages/next/src/rsc/data/queries/queryTerms.ts b/packages/next/src/rsc/data/queries/queryTerms.ts index de7781266..e3f2c66a8 100644 --- a/packages/next/src/rsc/data/queries/queryTerms.ts +++ b/packages/next/src/rsc/data/queries/queryTerms.ts @@ -15,7 +15,7 @@ export async function queryTerms< return result; } catch (error) { if (error instanceof Error) { - handleFetchError(error, config, query.path); + await handleFetchError(error, config, query.path); } throw error; } 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 0d8d524a8..be21d4109 100644 --- a/projects/wp-nextjs-app/src/app/(single)/[...path]/page.tsx +++ b/projects/wp-nextjs-app/src/app/(single)/[...path]/page.tsx @@ -6,11 +6,6 @@ const Single = async ({ params }: HeadstartWPRoute) => { params: { matchCurrentPath: false, }, - options: { - headers: { - cache: 'no-store', - }, - }, }); return ( diff --git a/projects/wp-nextjs-app/src/app/not-found.tsx b/projects/wp-nextjs-app/src/app/not-found.tsx new file mode 100644 index 000000000..0b6d8855c --- /dev/null +++ b/projects/wp-nextjs-app/src/app/not-found.tsx @@ -0,0 +1,13 @@ +import Link from 'next/link'; + +const NotFound = () => { + return ( +
+

Not Found

+

Could not find requested resource

+ Return Home +
+ ); +}; + +export default NotFound;