Skip to content
This repository was archived by the owner on Aug 27, 2026. It is now read-only.

perf(content): exclude content from list page data - #98

Merged
monotykamary merged 1 commit into
mainfrom
perf/reduce-page-data-size
Apr 3, 2025
Merged

monotykamary merged 1 commit into
mainfrom
perf/reduce-page-data-size

Conversation

@monotykamary

Copy link
Copy Markdown
Collaborator

Problem

Next.js build process showed a warning about large page data (>1MB) for list pages like /updates:

Warning: data for page "/[...slug]" (path "/updates") is 2.06 MB which exceeds the threshold of 1.05 MB, this amount of data can reduce performance.

Cause

The getStaticProps function in src/pages/[...slug].tsx was calling getAllMarkdownContents twice:

  1. Once to fetch all memos for getRootLayoutPageProps (used to build the directory tree).
  2. A second time (for directory paths like /updates) to fetch child memos for the list page.

Both calls loaded the full content of the markdown files into memory via fs.readFileSync within getAllMarkdownContents. This entire dataset, including content not needed for the directory tree or the list page view, was being serialized into the page props, causing the large data size.

Solution

  1. Modified getAllMarkdownContents (src/lib/content/memo.ts):
    • Added an optional options object parameter with an includeContent: boolean flag (defaults to true).
    • The function now only includes the content property in the returned IMemoItem object if includeContent is true.
  2. Modified getStaticProps (src/pages/[...slug].tsx):
    • Updated both calls to getAllMarkdownContents to pass { includeContent: false }.
      • The first call (for layout props) doesn't need content because buildDirectorTree only uses metadata.
      • The second call (for list pages) doesn't need content because the page only displays memo titles and links.

Expected Outcome

This change significantly reduces the amount of data included in the page props for directory list pages by excluding unnecessary markdown content. This should resolve the large page data warning and improve build performance and potentially runtime performance for these pages.

@monotykamary monotykamary changed the title Perf(content): Exclude content from list page data perf(content): exclude content from list page data Apr 3, 2025
@monotykamary
monotykamary merged commit 6911e2b into main Apr 3, 2025
@monotykamary
monotykamary deleted the perf/reduce-page-data-size branch April 18, 2025 10:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant