Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Set 404 Revalidate timer to 900 seconds. #1639

Merged
merged 8 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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: 3 additions & 3 deletions examples/next/faustwp-getting-started/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
},
"dependencies": {
"@apollo/client": "^3.6.6",
"@faustwp/cli": "^1.2.0",
"@faustwp/core": "^1.2.0",
"@wordpress/base-styles": "^4.26.0",
"@faustwp/cli": "1.2.0",
"@faustwp/core": "1.2.0",
theodesp marked this conversation as resolved.
Show resolved Hide resolved
"@wordpress/base-styles": "^4.36.0",
"@wordpress/block-library": "^7.19.0",
"classnames": "^2.3.1",
"graphql": "^16.6.0",
Expand Down
123 changes: 120 additions & 3 deletions 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
theodesp marked this conversation as resolved.
Show resolved Hide resolved
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
Loading