Skip to content

Commit 832bb43

Browse files
committed
docs(config): document maxIterations option
- Add iteration limit section to EN and ID rendering docs - Add maxIterations option to EN and ID routes configuration - Add template iteration limit section to EN and ID server configuration
1 parent a88d9d3 commit 832bb43

6 files changed

Lines changed: 82 additions & 0 deletions

File tree

docs/en/getting-started/routes-configuration.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ const router = new Router({
4444
})
4545
```
4646

47+
### `maxIterations`
48+
49+
Maximum number of iterations allowed per <code v-pre>{{#each}}</code> block in DVE templates. Prevents event loop starvation from unbounded template rendering. Default is `100_000`. If exceeded, the engine throws and the server responds with **500 Internal Server Error**.
50+
51+
```typescript
52+
const router = new Router({
53+
routesDir: 'routes',
54+
viewsDir: './views',
55+
maxIterations: 50_000
56+
})
57+
```
58+
59+
For datasets larger than the limit, use [`streamRender`](/en/rendering/streaming) instead. For CPU-intensive rendering, consider offloading to a [worker pool](/en/core-concepts/worker-pool).
60+
4761
## Supported File Extensions
4862

4963
Deserve automatically detects and supports these file extensions:

docs/en/getting-started/server-configuration.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ await router.serve(8000)
7070

7171
Omit `requestTimeoutMs` for no timeout (default).
7272

73+
## Template Iteration Limit
74+
75+
You can limit the number of iterations per <code v-pre>{{#each}}</code> block in DVE templates. This prevents event loop starvation from unbounded template rendering. Default is `100_000`:
76+
77+
```typescript
78+
const router = new Router({
79+
viewsDir: './views',
80+
maxIterations: 50_000
81+
})
82+
await router.serve(8000)
83+
```
84+
85+
If a template exceeds the limit, the server responds with **500 Internal Server Error**. For large datasets, use [`streamRender`](/en/rendering/streaming) instead. For CPU-intensive rendering, consider offloading to a [worker pool](/en/core-concepts/worker-pool).
86+
7387
## Graceful Shutdown
7488

7589
Use `AbortSignal` for graceful server shutdown:

docs/en/rendering/index.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,19 @@ await ctx.render('template', newData) // Fast
213213

214214
**Note**: Cache is only for template compilation, not data or backend logic.
215215

216+
### Iteration Limit
217+
218+
Each <code v-pre>{{#each}}</code> block is limited to `100_000` iterations by default. This prevents event loop starvation from unbounded loops. Configure via `maxIterations`:
219+
220+
```typescript
221+
const router = new Router({
222+
viewsDir: './views',
223+
maxIterations: 200_000
224+
})
225+
```
226+
227+
If a loop exceeds the limit, the engine throws and the server responds with **500**. For very large datasets, use [streaming rendering](/en/rendering/streaming) instead. For CPU-intensive rendering, consider offloading to a [worker pool](/en/core-concepts/worker-pool).
228+
216229
## Error Handling
217230

218231
```typescript

docs/id/getting-started/routes-configuration.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ const router = new Router({
4444
})
4545
```
4646

47+
### `maxIterations`
48+
49+
Jumlah maksimum iterasi yang diizinkan per blok <code v-pre>{{#each}}</code> di template DVE. Mencegah event loop starvation dari rendering template tanpa batas. Default adalah `100_000`. Jika terlampaui, engine akan throw dan server merespons **500 Internal Server Error**.
50+
51+
```typescript
52+
const router = new Router({
53+
routesDir: 'routes',
54+
viewsDir: './views',
55+
maxIterations: 50_000
56+
})
57+
```
58+
59+
Untuk dataset lebih besar dari limit, gunakan [`streamRender`](/id/rendering/streaming). Untuk rendering yang CPU-intensive, pertimbangkan untuk offload ke [worker pool](/id/core-concepts/worker-pool).
60+
4761
## Ekstensi File Yang Didukung
4862

4963
Deserve secara otomatis mendeteksi dan mendukung ekstensi file ini:

docs/id/getting-started/server-configuration.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ await router.serve(8000)
7070

7171
Omit `requestTimeoutMs` untuk tanpa timeout (default).
7272

73+
## Batas Iterasi Template
74+
75+
Anda bisa membatasi jumlah iterasi per blok <code v-pre>{{#each}}</code> di template DVE. Ini mencegah event loop starvation dari rendering template tanpa batas. Default adalah `100_000`:
76+
77+
```typescript
78+
const router = new Router({
79+
viewsDir: './views',
80+
maxIterations: 50_000
81+
})
82+
await router.serve(8000)
83+
```
84+
85+
Jika template melebihi limit, server merespons **500 Internal Server Error**. Untuk dataset besar, gunakan [`streamRender`](/id/rendering/streaming). Untuk rendering yang CPU-intensive, pertimbangkan untuk offload ke [worker pool](/id/core-concepts/worker-pool).
86+
7387
## Graceful Shutdown
7488

7589
Gunakan `AbortSignal` untuk graceful server shutdown:

docs/id/rendering/index.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,19 @@ await ctx.render('template', newData) // Cepat
213213

214214
**Catatan**: Cache hanya untuk kompilasi template, bukan data atau logic backend.
215215

216+
### Batas Iterasi
217+
218+
Setiap blok <code v-pre>{{#each}}</code> dibatasi `100_000` iterasi secara default. Ini mencegah event loop starvation dari loop tanpa batas. Konfigurasi via `maxIterations`:
219+
220+
```typescript
221+
const router = new Router({
222+
viewsDir: './views',
223+
maxIterations: 200_000
224+
})
225+
```
226+
227+
Jika loop melebihi limit, engine akan throw dan server merespons **500**. Untuk dataset sangat besar, gunakan [streaming rendering](/id/rendering/streaming). Untuk rendering yang CPU-intensive, pertimbangkan untuk offload ke [worker pool](/id/core-concepts/worker-pool).
228+
216229
## Error Handling
217230

218231
```typescript

0 commit comments

Comments
 (0)