Skip to content

Commit

Permalink
fix: short revalidation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeday committed Sep 17, 2024
1 parent 164f1d3 commit 1cefd50
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
11 changes: 5 additions & 6 deletions utilsApi/get-default-static-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { ParsedUrlQuery } from 'querystring';

import Metrics from 'utilsApi/metrics';
import { fetchExternalManifest } from './fetch-external-manifest';
import { config } from 'config';

export const getDefaultStaticProps = <
P extends { [key: string]: any } = { [key: string]: any },
Expand All @@ -11,15 +12,14 @@ export const getDefaultStaticProps = <
>(
custom?: GetStaticProps<P, Q, D>,
): GetStaticProps<P & { ___prefetch_manifest___?: object }, Q, D> => {
let shouldZeroRevalidate = true;
return async (context) => {
/// common props
const { ___prefetch_manifest___, revalidate } =
await fetchExternalManifest();
const { ___prefetch_manifest___ } = await fetchExternalManifest();
const props = ___prefetch_manifest___ ? { ___prefetch_manifest___ } : {};
const base = {
props,
revalidate: shouldZeroRevalidate ? 1 : revalidate,
// because next only remembers first value, default to short revalidation period
revalidate: config.ERROR_REVALIDATION_SECONDS,
};

/// custom getStaticProps
Expand All @@ -35,11 +35,10 @@ export const getDefaultStaticProps = <

/// metrics
console.debug(
`[getDefaultStaticProps] running revalidation, next revalidation in ${base.revalidate}`,
`[getDefaultStaticProps] running revalidation, next revalidation in ${result.revalidate}`,
);
Metrics.request.ssrCounter.labels({ revalidate: base.revalidate }).inc(1);

shouldZeroRevalidate = false;
return result;
};
};
6 changes: 3 additions & 3 deletions utilsApi/rpcFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ export const rpcFactory = ({
.pipe(sizeLimit)
.on('error', (error) => {
if (error instanceof SizeTooLargeError) {
console.warn('[rpcFactory] RPC response too large', {
request: JSON.stringify(requests),
});
console.warn(
`[rpcFactory] RPC response too large: ${JSON.stringify(requests)}`,
);
res.statusCode = 413; // Payload Too Large
res.end(error.message);
} else {
Expand Down

0 comments on commit 1cefd50

Please sign in to comment.