@@ -22,14 +22,18 @@ import {SSGConcurrency} from './ssgEnv';
2222import { writeStaticFile } from './ssgUtils' ;
2323import { createSSGRequire } from './ssgNodeRequire' ;
2424import type { SSGParams } from './ssgParams' ;
25- import type { AppRenderer , AppRenderResult } from '../common' ;
25+ import type {
26+ AppRenderer ,
27+ PageCollectedData ,
28+ PageCollectedDataInternal ,
29+ } from '../common' ;
2630import type { HtmlMinifier } from '@docusaurus/bundler' ;
2731
2832export type SSGSuccess = {
2933 success : true ;
3034 pathname : string ;
3135 result : {
32- collectedData : AppRenderResult [ 'collectedData' ] ;
36+ collectedData : PageCollectedData ;
3337 warnings : string [ ] ;
3438 // html: we don't include it on purpose!
3539 // we don't need to aggregate all html contents in memory!
@@ -144,6 +148,26 @@ export async function loadSSGRenderer({
144148 } ;
145149}
146150
151+ // We reduce the page collected data structure after the HTML file is written
152+ // Some data (modules, metadata.internal) is only useful to create the HTML file
153+ // It's not useful to aggregate that collected data in memory
154+ // Keep this data structure as small as possible
155+ // See https://github.com/facebook/docusaurus/pull/11162
156+ function reduceCollectedData (
157+ pageCollectedData : PageCollectedDataInternal ,
158+ ) : PageCollectedData {
159+ // We re-create the object from scratch
160+ // We absolutely want to avoid TS duck typing
161+ return {
162+ anchors : pageCollectedData . anchors ,
163+ metadata : {
164+ public : pageCollectedData . metadata . public ,
165+ helmet : pageCollectedData . metadata . helmet ,
166+ } ,
167+ links : pageCollectedData . links ,
168+ } ;
169+ }
170+
147171async function generateStaticFile ( {
148172 pathname,
149173 appRenderer,
@@ -176,11 +200,14 @@ async function generateStaticFile({
176200 content : minifierResult . code ,
177201 params,
178202 } ) ;
203+
204+ const collectedData = reduceCollectedData ( appRenderResult . collectedData ) ;
205+
179206 return {
180207 success : true ,
181208 pathname,
182209 result : {
183- collectedData : appRenderResult . collectedData ,
210+ collectedData,
184211 // As of today, only the html minifier can emit SSG warnings
185212 warnings : minifierResult . warnings ,
186213 } ,
0 commit comments