Skip to content

Commit f299196

Browse files
authored
docs(jsx-renderer): add example of resolving Suspense with isSSGContext (#845)
1 parent 967006f commit f299196

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

docs/helpers/ssg.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,19 @@ app.get(
215215
)
216216
```
217217

218+
### isSSGContext
219+
220+
`isSSGContext` is a helper function that returns `true` if the current application is running within the SSG context triggered by `toSSG`.
221+
222+
```ts
223+
app.get('/page', (c) => {
224+
if (isSSGContext(c)) {
225+
return c.text('This is generated by SSG')
226+
}
227+
return c.text('This is served dynamically')
228+
})
229+
```
230+
218231
### disableSSG
219232

220233
Routes with the `disableSSG` middleware set are excluded from static file generation by `toSSG`.

docs/middleware/builtin/jsx-renderer.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,28 @@ app.use(
146146
)
147147
```
148148

149+
As a concrete example, you can use this to disable streaming when generating static sites (SSG) with `<Suspense>`, by using the [`isSSGContext`](/docs/helpers/ssg#isssgcontext) helper:
150+
151+
```tsx
152+
app.use(
153+
'*',
154+
jsxRenderer(
155+
({ children }) => {
156+
return (
157+
<div>
158+
<Suspense fallback={'loading...'}>
159+
<Component />
160+
</Suspense>
161+
</div>
162+
)
163+
},
164+
(c) => ({
165+
stream: !isSSGContext(c),
166+
})
167+
)
168+
)
169+
```
170+
149171
## Nested Layouts
150172

151173
The `Layout` component enables nesting the layouts.

0 commit comments

Comments
 (0)