Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
f869143
feat: app router poc
nicholasio May 24, 2024
5df7f07
chore: adjust exports conditions
nicholasio May 27, 2024
e7dc174
wip: wip
nicholasio Jun 6, 2024
461a648
fix: merge conflicts
nicholasio Jun 17, 2024
fb075b2
feat: initial pass at fetch functions
nicholasio Jun 20, 2024
41f73e3
feat: more progress on data fetching on app router
nicholasio Jun 22, 2024
e4055dd
feat: fix tests and code sharing
nicholasio Jun 23, 2024
fb0e26b
feat: exploring multi site support in app router
nicholasio Jun 23, 2024
3b73131
feat(data-fetching): wrapping up first pass at data-fetching
nicholasio Jun 24, 2024
26c35a7
fix: removing hooks package
nicholasio Jun 24, 2024
0a0284b
chore: update workspaces config
nicholasio Jun 24, 2024
ce3ec6d
fix: build error
nicholasio Jun 24, 2024
8f078f6
feat(data-fetching): fetchAppSettings & queryAppSettings
nicholasio Jun 24, 2024
5a183aa
fix: build issue
nicholasio Jun 25, 2024
e5f741e
feat(data-fetching): queryAuthorArchive
nicholasio Jun 25, 2024
6f68dd8
feat: tag page
nicholasio Jun 25, 2024
21990bb
feat(data-fetching): querySearch and queryTerms
nicholasio Jun 25, 2024
30f94c7
feat(data-fetching): queryPostOrPosts
nicholasio Jun 25, 2024
156072f
fix: build error with pages router project
nicholasio Jun 25, 2024
fe647b5
fix: another build issue
nicholasio Jun 25, 2024
c3cf144
feat(data-fetching): issue a not-found if no redirect is found
nicholasio Jun 25, 2024
d96e10c
test: add more data-fetching tests
nicholasio Jun 25, 2024
3006585
test: more tests
nicholasio Jun 26, 2024
46971cb
test: add more tests
nicholasio Jun 28, 2024
dad963d
chore: changeset
nicholasio Jun 28, 2024
80c3576
chore: fix lock file
nicholasio Jun 28, 2024
a7eebf7
fix: re-export other server-compatible components
nicholasio Jun 28, 2024
96a5c2f
fix: remove unnecessary cache headers
nicholasio Jun 28, 2024
cd76604
feat: first pass at previewRouteHandler
nicholasio Jul 1, 2024
8b2858b
feat: preview fixes
nicholasio Jul 1, 2024
d7cc96f
feat: add PreviewIndicator component
nicholasio Jul 3, 2024
c945166
test: adding test for queryPost preview logic
nicholasio Jul 3, 2024
b01a4ba
chore: update re-exports
nicholasio Jul 3, 2024
631dbdc
fix: config loading for route handlers
nicholasio Jul 3, 2024
5a787aa
docs: update jsdocs
nicholasio Jul 3, 2024
2a17cf1
feat: update single route to render post content
nicholasio Jul 4, 2024
98bae20
chore: changeset
nicholasio Jul 4, 2024
08ae034
feat: revalidateRouteHandler
nicholasio Jul 9, 2024
db7486e
refactor: small refactor
nicholasio Jul 9, 2024
ad6beaf
test: first pass at setting a source url and mocking requests based o…
nicholasio Jul 9, 2024
a7dea3a
test: updating tests of next package
nicholasio Jul 9, 2024
e38627b
test: fix tests
nicholasio Jul 9, 2024
bd70af9
test: fixing more tests
nicholasio Jul 9, 2024
2dc5a06
test: fix last test
nicholasio Jul 9, 2024
f86a8cb
fix: can't use force-static with draft mode
nicholasio Jul 9, 2024
a91a47d
test: add tests for previewRouteHandler
nicholasio Jul 9, 2024
b585500
test: previewRouteHandler tests
nicholasio Jul 11, 2024
68db922
test: tests for revalidateRouteHandler
nicholasio Jul 11, 2024
163fbcf
Merge branch 'develop' into feature/app-router-preview-handler
nicholasio Jul 11, 2024
69f8b0e
chore: fix deps
nicholasio Jul 11, 2024
1cd5087
App Router Handler Tests (#799)
nicholasio Jul 13, 2024
f147737
App Router - Revalidate Handler + Test Refactor to use sourceUrl (#798)
nicholasio Jul 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/cyan-fans-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@headstartwp/core": minor
"@headstartwp/next": minor
---

Introducing previewRouteHandler to handle preview in Next.js App Router
6 changes: 6 additions & 0 deletions .changeset/moody-emus-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@headstartwp/core": minor
"@headstartwp/next": minor
---

Introducing `revalidateRouteHandler` for handling revalidate requests in Route Handlers (App Router)
122 changes: 93 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
"lint": "eslint src/"
},
"devDependencies": {
"@testing-library/dom": "^8.19.0",
"@testing-library/react": "^13.4.0",
"@testing-library/dom": "^10.3.1",
"@testing-library/react": "^16.0.0",
"@types/jest": "^29.0.3",
"@types/node-fetch": "^2.5.3",
"expect-type": "^0.15.0",
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/data/fetchFn/__tests__/fetchAppSettings.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { expectTypeOf } from 'expect-type';
import { AppEntity, EndpointParams } from '../..';
import { fetchAppSettings } from '../fetchAppSettings';
import { setHeadstartWPConfig } from '../../../utils';

describe('fetchAppSettings', () => {
beforeAll(() => {
setHeadstartWPConfig({
sourceUrl: 'https://js1.10up.com',
useWordPressPlugin: true,
});
});

it('allows overriding types', async () => {
interface MyAppEntity extends AppEntity {
myCustomSetting: string;
Expand Down
21 changes: 10 additions & 11 deletions packages/core/src/data/fetchFn/__tests__/fetchPost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ import { PostParams } from '../..';
import { DRAFT_POST_ID, VALID_AUTH_TOKEN } from '../../../../test/server-handlers';
import { PostEntity } from '../../types';
import { fetchPost } from '../fetchPost';
import { setHeadstartWPConfig } from '../../../utils';

describe('fetchPost', () => {
beforeAll(() => {
setHeadstartWPConfig({
sourceUrl: 'https://js1.10up.com',
useWordPressPlugin: true,
});
});

it('fetches data properly', async () => {
const { data } = await fetchPost({
params: { slug: 'modi-qui-dignissimos-sed-assumenda-sint-iusto' },
Expand Down Expand Up @@ -86,11 +94,7 @@ describe('fetchPost', () => {

it('reads param from the url and sets isMainQuery flag', async () => {
const result = await fetchPost({
path: '/modi-qui-dignissimos-sed-assumenda-sint-iusto/',
params: {
fullPath:
'https://js1.10up.com/2020/05/07/modi-qui-dignissimos-sed-assumenda-sint-iusto/',
},
path: '/2020/05/07/modi-qui-dignissimos-sed-assumenda-sint-iusto/',
});

expect(result.data.post.slug).toBe('modi-qui-dignissimos-sed-assumenda-sint-iusto');
Expand Down Expand Up @@ -125,12 +129,7 @@ describe('fetchPost', () => {

it('matches post.link with fullPath when set', async () => {
const { data } = await fetchPost({
path: '/modi-qui-dignissimos-sed-assumenda-sint-iusto',
params: {
// force post path mapping against this path
fullPath:
'https://js1.10up.com/2020/05/07/modi-qui-dignissimos-sed-assumenda-sint-iusto',
},
path: '/2020/05/07/modi-qui-dignissimos-sed-assumenda-sint-iusto',
});

expect(data.post.slug).toBe('modi-qui-dignissimos-sed-assumenda-sint-iusto');
Expand Down
24 changes: 13 additions & 11 deletions packages/core/src/data/fetchFn/__tests__/fetchPosts.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { expectTypeOf } from 'expect-type';

import { PostEntity, PostsArchiveParams, fetchPosts } from '../..';
import { setHeadlessConfig } from '../../../utils';
import { setHeadstartWPConfig } from '../../../utils';

describe('fetchPosts', () => {
beforeEach(() => {
setHeadlessConfig({
beforeAll(() => {
setHeadstartWPConfig({
sourceUrl: 'https://js1.10up.com',
useWordPressPlugin: true,
});
});
Expand Down Expand Up @@ -128,16 +129,17 @@ describe('fetchPosts', () => {
it('throws params.matchArchivepath is true and path does not match', async () => {
await expect(
fetchPosts({
path: 'https://js1.10up.com/category/asdasd/uncategorized',
path: '/category/asdasd/uncategorized',
params: { category: 'uncategorized', per_page: 1, matchArchivePath: true },
}),
).rejects.toThrow(
`Posts were found but did not match current path: "https://js1.10up.com/category/asdasd/uncategorized"`,
`Posts were found but did not match current path: "/category/asdasd/uncategorized"`,
);
});

it('throws matchArchivepath config option is true and path does not match', async () => {
setHeadlessConfig({
setHeadstartWPConfig({
sourceUrl: 'https://js1.10up.com',
useWordPressPlugin: true,
customTaxonomies: (defaultTaxonomies) => {
return defaultTaxonomies.map((taxonomy) => ({
Expand All @@ -149,16 +151,17 @@ describe('fetchPosts', () => {

await expect(
fetchPosts({
path: 'https://js1.10up.com/category/asdasd/uncategorized',
path: '/category/asdasd/uncategorized',
params: { category: 'uncategorized', per_page: 2 },
}),
).rejects.toThrow(
`Posts were found but did not match current path: "https://js1.10up.com/category/asdasd/uncategorized"`,
`Posts were found but did not match current path: "/category/asdasd/uncategorized"`,
);
});

it('does not throws when matchArchivepath config option is true and path matches', async () => {
setHeadlessConfig({
setHeadstartWPConfig({
sourceUrl: 'https://js1.10up.com',
useWordPressPlugin: true,
customTaxonomies: (defaultTaxonomies) => {
return defaultTaxonomies.map((taxonomy) => ({
Expand All @@ -169,8 +172,7 @@ describe('fetchPosts', () => {
});

const { data } = await fetchPosts({
// Need this bc source url removal is not working in the tests
path: 'https://js1.10up.com/category/uncategorized',
path: '/category/uncategorized',
params: {
category: 'uncategorized',
per_page: 1,
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/data/fetchFn/__tests__/fetchPostsOrPosts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import { PostEntity } from '../../types';
import { fetchPostOrPosts } from '../fetchPostOrPosts';

describe('fetchPostsOrPosts', () => {
setHeadstartWPConfig({
useWordPressPlugin: true,
beforeAll(() => {
setHeadstartWPConfig({
sourceUrl: 'https://js1.10up.com',
useWordPressPlugin: true,
});
});

it('fetches data properly (archive)', async () => {
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/data/fetchFn/__tests__/fetchSearch.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import { expectTypeOf } from 'expect-type';

import { PostSearchEntity, SearchParams, TermSearchEntity, fetchSearch } from '../..';
import { setHeadstartWPConfig } from '../../../utils';

describe('fetchSearch', () => {
beforeAll(() => {
setHeadstartWPConfig({
sourceUrl: 'https://js1.10up.com',
useWordPressPlugin: true,
});
});

it('returns empty results instead of throwing if not found', async () => {
const { data } = await fetchSearch({ params: { search: 'not-found' } });

Expand Down
Loading