Skip to content

Commit e949724

Browse files
committed
grammar and changeset
1 parent 2e8ecae commit e949724

File tree

5 files changed

+37
-32
lines changed

5 files changed

+37
-32
lines changed

.changeset/hot-eyes-sink.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export default defineConfig({
4242

4343
The third sub-feature is content caching. It allows to cache **values** of nodes during the rendering phase. Among the new tools, this seemed to be the least useful, so for now it's not possible to control its size:
4444

45+
When disabled, the pool engine won't cache strings, but only types.
46+
4547
```js
4648
// astro.config.mjs
4749
export default defineConfig({

packages/astro/src/runtime/server/render/queue/builder.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ export async function buildRenderQueue(
4747

4848
// Process nodes depth-first
4949
while (stack.length > 0) {
50-
const item = stack.pop()!;
50+
const item = stack.pop();
51+
if (!item) {
52+
continue;
53+
}
5154
let { node, parent } = item;
5255

5356
// Handle promises immediately (wait for resolution)
@@ -71,7 +74,7 @@ export async function buildRenderQueue(
7174
// Handle different node types
7275
if (typeof node === 'string') {
7376
// Plain text content - use content-aware caching
74-
// acquire('text', ...) returns TextNode, so we can safely assert
77+
// Acquire('text', ...) returns TextNode, so we can safely assert
7578
const queueNode = pool.acquire('text', node) as TextNode;
7679
queueNode.content = node;
7780
queue.nodes.push(queueNode);
@@ -105,10 +108,10 @@ export async function buildRenderQueue(
105108
continue;
106109
}
107110

108-
// Handle JSX vnodes (from MDX or JSX expressions)
111+
// Handle JSX VNodes (from MDX or JSX expressions)
109112
if (isVNode(node)) {
110-
// Process JSX vnode through the JSX builder
111-
// This will recursively handle the vnode and its children
113+
// Process JSX VNode through the JSX builder
114+
// This will push the VNode and its children onto the stack for processing
112115
renderJSXToQueue(node, result, queue, pool, stack, parent, item.metadata);
113116
continue;
114117
}
@@ -138,7 +141,7 @@ export async function buildRenderQueue(
138141
const expressions = node['expressions'];
139142

140143
// Push in forward order - stack pop() will reverse, then final reverse() corrects it
141-
// Push first html part - mark as HTMLString so it won't be escaped
144+
// Push first HTML part - mark as HTMLString so it won't be escaped
142145
if (htmlParts[0]) {
143146
const htmlString = queue.htmlStringCache
144147
? queue.htmlStringCache.getOrCreate(htmlParts[0])
@@ -150,11 +153,11 @@ export async function buildRenderQueue(
150153
});
151154
}
152155

153-
// Interleave expressions and html parts
154-
for (let i = 0; i < expressions.length; i++) {
156+
// Interleave expressions and HTML parts
157+
for (let i = 0; i < expressions.length; i = i + 1) {
155158
// Push expression
156159
stack.push({ node: expressions[i], parent, metadata: item.metadata });
157-
// Push html part after expression - mark as HTMLString
160+
// Push HTML part after expression - mark as HTMLString
158161
if (htmlParts[i + 1]) {
159162
const htmlString = queue.htmlStringCache
160163
? queue.htmlStringCache.getOrCreate(htmlParts[i + 1])

packages/astro/src/runtime/server/render/queue/jsx-builder.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ export function resetJSXQueueStats() {
4646
}
4747

4848
/**
49-
* Processes JSX vnodes and adds them to the render queue.
49+
* Processes JSX VNodes and adds them to the render queue.
5050
* Unlike renderJSX(), this doesn't build strings recursively -
5151
* it pushes nodes directly to the queue for batching and memory efficiency.
5252
*
5353
* This function handles JSX created by astro:jsx (JSX in .astro files).
54-
* It converts vnodes to queue nodes, enabling content-aware pooling and batching.
54+
* It converts VNodes to queue nodes, enabling content-aware pooling and batching.
5555
*
56-
* @param vnode - JSX vnode to process
56+
* @param vnode - JSX VNode to process
5757
* @param result - SSR result context
5858
* @param queue - Queue to append nodes to
5959
* @param pool - Node pool for memory efficiency
@@ -71,7 +71,7 @@ export function renderJSXToQueue(
7171
metadata?: StackItem['metadata'],
7272
): void {
7373
// Track that JSX queue rendering is being used
74-
jsxQueueStats.vnodeCount++;
74+
jsxQueueStats.vnodeCount = jsxQueueStats.vnodeCount + 1;
7575

7676
// Handle primitive types
7777
if (vnode instanceof HTMLString) {
@@ -106,13 +106,13 @@ export function renderJSXToQueue(
106106
// Handle arrays - push each item to stack
107107
if (Array.isArray(vnode)) {
108108
// Push in reverse order so they're popped in correct order
109-
for (let i = vnode.length - 1; i >= 0; i--) {
109+
for (let i = vnode.length - 1; i >= 0; i = i - 1) {
110110
stack.push({ node: vnode[i], parent, metadata });
111111
}
112112
return;
113113
}
114114

115-
// Handle vnodes
115+
// Handle VNodes
116116
if (!isVNode(vnode)) {
117117
// Fallback: convert to string
118118
const str = String(vnode);
@@ -150,15 +150,15 @@ function handleVNode(
150150

151151
// Astro component factory
152152
if (isAstroComponentFactory(vnode.type)) {
153-
jsxQueueStats.componentCount++;
153+
jsxQueueStats.componentCount = jsxQueueStats.componentCount + 1;
154154
const factory = vnode.type;
155155
let props: Record<string, any> = {};
156156
let slots: Record<string, any> = {};
157157

158158
for (const [key, value] of Object.entries(vnode.props ?? {})) {
159159
if (key === 'children' || (value && typeof value === 'object' && value['$$slot'])) {
160160
// Slots need to return rendered content
161-
// We create a function that renders the JSX vnode to string
161+
// We create a function that renders the JSX VNode to string
162162
slots[key === 'children' ? 'default' : key] = () => renderJSX(result, value);
163163
} else {
164164
props[key] = value;
@@ -177,7 +177,7 @@ function handleVNode(
177177

178178
// HTML element (string type like 'div', 'span')
179179
if (typeof vnode.type === 'string' && vnode.type !== ClientOnlyPlaceholder) {
180-
jsxQueueStats.elementCount++;
180+
jsxQueueStats.elementCount = jsxQueueStats.elementCount + 1;
181181
renderHTMLElement(vnode, result, queue, pool, stack, parent, metadata);
182182
return;
183183
}
@@ -223,7 +223,7 @@ function renderHTMLElement(
223223
const isVoidElement = (children == null || children === '') && voidElementNames.test(tag);
224224

225225
if (isVoidElement) {
226-
// Self-closing element as html-string (cached by content)
226+
// Self-closing element as HTML-string (cached by content)
227227
const html = `<${tag}${attrs}/>`;
228228
const node = pool.acquire('html-string', html) as HtmlStringNode;
229229
node.html = html;
@@ -232,7 +232,7 @@ function renderHTMLElement(
232232
}
233233

234234
// Non-void element: open tag + children + close tag
235-
// Build opening tag as html-string (cached by content)
235+
// Build opening tag as HTML-string (cached by content)
236236
const openTag = `<${tag}${attrs}>`;
237237
const openTagHtml = queue.htmlStringCache
238238
? queue.htmlStringCache.getOrCreate(openTag)
@@ -246,7 +246,7 @@ function renderHTMLElement(
246246
stack.push({ node: processedChildren, parent, metadata });
247247
}
248248

249-
// Create closing tag as html-string (cached by content)
249+
// Create closing tag as HTML-string (cached by content)
250250
const closeTag = `</${tag}>`;
251251
const closeTagHtml = queue.htmlStringCache
252252
? queue.htmlStringCache.getOrCreate(closeTag)

packages/astro/src/runtime/server/render/queue/pool.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,24 @@ export class NodePool {
6060
*
6161
* @param maxSize - Maximum number of nodes to keep in the pool (default: 1000)
6262
* @param enableStats - Enable statistics tracking (default: false for performance)
63-
* @param enableContentCache - Enable content-aware caching for text/html nodes (default: true)
63+
* @param enableContentCache - Enable content-aware caching for text/HTML nodes (default: true)
6464
*/
6565
constructor(maxSize = 1000, enableContentCache = false, enableStats = false) {
6666
this.maxSize = maxSize;
6767
this.enableStats = enableStats;
6868
this.enableContentCache = enableContentCache;
6969
if (maxSize > 0) {
70-
// Warm up cache only if the pool size is bigger than 0. We treat zero as if there's no pool.
70+
// Warm up cache only if the pool size is greater than 0. We treat zero as if there's no pool.
7171
this.warmCache([...COMMON_HTML_PATTERNS]);
7272
}
7373
}
7474

7575
/**
76-
* Acquires a queue node from the pool or creates a new one if pool is empty.
77-
* Supports content-aware caching for text and html-string nodes.
76+
* Acquires a queue node from the pool or creates a new one if the pool is empty.
77+
* Supports content-aware caching for text and HTML-string nodes.
7878
*
7979
* @param type - The type of queue node to create
80-
* @param content - Optional content for content-aware caching (text or html)
80+
* @param content - Optional content for content-aware caching (text or HTML)
8181
* @returns A queue node ready to be populated with data
8282
*/
8383
acquire(type: QueueNode['type'], content?: string): QueueNode {
@@ -179,7 +179,7 @@ export class NodePool {
179179
this.stats.releasedDropped = this.stats.releasedDropped + 1;
180180
}
181181
}
182-
// If pool is full, let the node be garbage collected
182+
// If the pool is full, let the node be garbage collected
183183
}
184184

185185
/**
@@ -336,8 +336,8 @@ export const COMMON_HTML_PATTERNS = [
336336
] as const;
337337

338338
/**
339-
* Returns an instance of the `NodePool` based on its configuration
340-
* @param config
339+
* Returns an instance of the `NodePool` based on its configuration.
340+
* @param config - The queued rendering configuration from the SSR manifest
341341
*/
342342
export function newNodePool(
343343
config: NonNullable<SSRManifest['experimentalQueuedRendering']>,

packages/astro/src/runtime/server/render/queue/renderer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { QueueNode, RenderQueue } from './types.js';
66
/**
77
* Renders a queue of nodes to a destination.
88
* This function processes nodes sequentially with batching optimization.
9-
* Consecutive batchable nodes (text, html-string, simple elements) are
9+
* Consecutive batchable nodes (text, HTML-string, simple elements) are
1010
* combined into a single write to reduce overhead.
1111
*
1212
* @param queue - The render queue to process
@@ -32,7 +32,7 @@ export async function renderQueue(
3232
const batchStart = i;
3333
while (i < queue.nodes.length && canBatch(queue.nodes[i])) {
3434
batchBuffer += renderNodeToString(queue.nodes[i]);
35-
i++;
35+
i = i + 1;
3636
}
3737

3838
// Flush accumulated batch
@@ -58,7 +58,7 @@ export async function renderQueue(
5858
pool.release(node);
5959
}
6060

61-
i++;
61+
i = i + 1;
6262
}
6363
} catch (error) {
6464
// Stop on first error as requested

0 commit comments

Comments
 (0)