Skip to content

Commit 0c2ac8a

Browse files
committed
refactor(readme): avoid computing truncation check unnecessarily
Move the length comparison into the if condition so JS short-circuits past it when the earlier checks already trigger the jsDelivr fetch.
1 parent cbba528 commit 0c2ac8a

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

server/utils/readme-loaders.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ export const resolvePackageReadmeSource = defineCachedFunction(
7979

8080
const hasValidNpmReadme = readmeContent && readmeContent !== NPM_MISSING_README_SENTINEL
8181

82-
const isLikelyTruncated =
83-
hasValidNpmReadme && readmeContent!.length >= NPM_README_TRUNCATION_THRESHOLD
84-
85-
if (!hasValidNpmReadme || !isStandardReadme(readmeFilename) || isLikelyTruncated) {
82+
if (
83+
!hasValidNpmReadme ||
84+
!isStandardReadme(readmeFilename) ||
85+
readmeContent!.length >= NPM_README_TRUNCATION_THRESHOLD
86+
) {
8687
const resolvedVersion = version ?? packageData['dist-tags']?.latest
8788
const jsdelivrReadme = await fetchReadmeFromJsdelivr(
8889
packageName,

0 commit comments

Comments
 (0)