Skip to content
Open
Changes from all 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
7 changes: 7 additions & 0 deletions packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,10 @@ function pushViewTransitionAttributes(
}

const styleNameCache: Map<string, PrecomputedChunk> = new Map();
// Keep this cache bounded for long-running server processes. Style property
// names are normally a small fixed set, so clearing on pathological growth
// preserves the fast path without retaining unbounded user-generated keys.
const MAX_STYLE_NAME_CACHE_SIZE = 1024;
function processStyleName(styleName: string): PrecomputedChunk {
const chunk = styleNameCache.get(styleName);
if (chunk !== undefined) {
Expand All @@ -1189,6 +1193,9 @@ function processStyleName(styleName: string): PrecomputedChunk {
const result = stringToPrecomputedChunk(
escapeTextForBrowser(hyphenateStyleName(styleName)),
);
if (styleNameCache.size >= MAX_STYLE_NAME_CACHE_SIZE) {
styleNameCache.clear();
}
styleNameCache.set(styleName, result);
return result;
}
Expand Down