Skip to content

Commit

Permalink
RFC: Set 404 Revalidate timer to 900 seconds. (#1639)
Browse files Browse the repository at this point in the history
* RFC: Set 404 Revalidate timer to 900 seconds.

* Review: Remove DEFAULT_ISR_REVALIDATE from getSitemapProps

* Refactor: Conditionally Add `revalidate` on non SSR requests.

* Update package.json

* Update package-lock.json
  • Loading branch information
theodesp authored Nov 17, 2023
1 parent a4190ad commit 50a8d08
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/next/faustwp-getting-started/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@apollo/client": "^3.6.6",
"@faustwp/cli": "^1.2.0",
"@faustwp/core": "^1.2.0",
"@wordpress/base-styles": "^4.26.0",
"@wordpress/base-styles": "^4.36.0",
"@wordpress/block-library": "^7.19.0",
"classnames": "^2.3.1",
"graphql": "^16.6.0",
Expand Down
119 changes: 118 additions & 1 deletion package-lock.json

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

1 change: 1 addition & 0 deletions packages/faustwp-core/src/getProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export async function getNextStaticProps<TProps>(
if (isBoolean(notFound) && notFound === true) {
return {
notFound,
revalidate: DEFAULT_ISR_REVALIDATE,
};
}

Expand Down
21 changes: 12 additions & 9 deletions packages/faustwp-core/src/getWordPressProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ function isSSR(
return (ctx as GetServerSidePropsContext).req !== undefined;
}

const createNotFound = (
ctx: GetStaticPropsContext,
revalidate?: number | boolean,
) => ({
notFound: true as const,
...(!isSSR(ctx) && { revalidate: revalidate ?? DEFAULT_ISR_REVALIDATE }),
});

export type WordPressTemplate = React.FC & {
query?: DocumentNode;
variables?: (
Expand Down Expand Up @@ -54,6 +62,7 @@ export async function getWordPressProps(
}
| {
notFound: true;
revalidate?: number | boolean | undefined;
}
> {
const { templates } = getConfig();
Expand Down Expand Up @@ -84,9 +93,7 @@ export async function getWordPressProps(
}) as string | null;

if (!resolvedUrl) {
return {
notFound: true,
};
return createNotFound(ctx, revalidate);
}

const seedQuery = hooks.applyFilters('seedQueryDocumentNode', SEED_QUERY, {
Expand All @@ -104,9 +111,7 @@ export async function getWordPressProps(
debugLog(`Seed Node for resolved url: "${resolvedUrl}": `, seedNode);

if (!seedNode) {
return {
notFound: true,
};
return createNotFound(ctx, revalidate);
}

infoLog(
Expand All @@ -117,9 +122,7 @@ export async function getWordPressProps(
const template = getTemplate(seedNode, templates);

if (!template) {
return {
notFound: true,
};
return createNotFound(ctx, revalidate);
}

let templateQueryRes;
Expand Down
2 changes: 1 addition & 1 deletion packages/faustwp-core/tests/getProps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('getProps', () => {
expect.assertions(1);
expect(
await getNextStaticProps({}, { Page: {}, notFound: true }),
).toStrictEqual({ notFound: true });
).toStrictEqual({ notFound: true, revalidate: 900 });
});

test('getNextStaticProps() handles `redirect`', async () => {
Expand Down

0 comments on commit 50a8d08

Please sign in to comment.