Skip to content

docs(react/isr): use getResponseHeaders in example#6265

Closed
FEgor04 wants to merge 8 commits into
TanStack:mainfrom
FEgor04:fix-middleware-result
Closed

docs(react/isr): use getResponseHeaders in example#6265
FEgor04 wants to merge 8 commits into
TanStack:mainfrom
FEgor04:fix-middleware-result

Conversation

@FEgor04

@FEgor04 FEgor04 commented Jan 1, 2026

Copy link
Copy Markdown
Contributor

I've faced an issue when trying to use cache middleware from ISR article.
Currently it uses result.response.headers to access response headers.
However it turns out that result.response is undefined, which causes, even though type annotations say that it is not. It seems like a bug, since TypeScript allows a code that leads to a runtime error.
See commit 6c6ec1b and screenshot below.
image

Then I tried to use result.headers, which is not present in RequestServerResult. Setting them did not work either. See commit 3b417f6
image

In the end I've tried using getResponseHeaders and it worked! See commit 52fc400
I've updated the ISR article in the docs to use getResponseHeaders. Not sure what to with result.response being undefined

Summary by CodeRabbit

  • Documentation
    • Updated React Start Incremental Static Regeneration guide with improved middleware header management patterns. The revised examples demonstrate a refined approach to response header modification using utility functions, providing clearer implementation guidance while preserving existing functionality.

✏️ Tip: You can customize this high-level summary in your review settings.

@github-actions github-actions Bot added the documentation Everything documentation related label Jan 1, 2026
@coderabbitai

coderabbitai Bot commented Jan 1, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The documentation for React Start's incremental static regeneration (ISR) guide was updated to demonstrate a refactored approach to header management. The example now imports and uses getResponseHeaders() from the React Start server utilities instead of directly modifying response headers, while maintaining the same functional outcome.

Changes

Cohort / File(s) Summary
Header Management Refactoring
docs/start/framework/react/guide/isr.md
Added import of getResponseHeaders from @tanstack/react-start/server; refactored middleware example to use getResponseHeaders() for setting Cache-Control header instead of direct result.response.headers modification

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 Headers now flow through the proper way,
getResponseHeaders() saves the day!
Cache-Control set with style and grace,
The example code finds its rightful place! ✨

Pre-merge checks

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely identifies the main change: updating the ISR documentation example to use the getResponseHeaders function.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud

nx-cloud Bot commented Jan 1, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit 0979757

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded <1s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 3s View ↗

☁️ Nx Cloud last updated this comment at 2026-01-07 08:21:05 UTC

@pkg-pr-new

pkg-pr-new Bot commented Jan 1, 2026

Copy link
Copy Markdown
More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@6265

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@6265

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@6265

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@6265

@tanstack/react-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@6265

@tanstack/react-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@6265

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@6265

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@6265

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@6265

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@6265

@tanstack/router-cli

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@6265

@tanstack/router-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@6265

@tanstack/router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@6265

@tanstack/router-devtools-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@6265

@tanstack/router-generator

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@6265

@tanstack/router-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@6265

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@6265

@tanstack/router-utils

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@6265

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@6265

@tanstack/solid-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@6265

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@6265

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@6265

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@6265

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@6265

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@6265

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@6265

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-fn-stubs@6265

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@6265

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@6265

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@6265

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@6265

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@6265

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@6265

@tanstack/vue-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router@6265

@tanstack/vue-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-devtools@6265

@tanstack/vue-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-ssr-query@6265

@tanstack/vue-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start@6265

@tanstack/vue-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-client@6265

@tanstack/vue-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-server@6265

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@6265

commit: 0979757

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
docs/start/framework/react/guide/isr.md (1)

117-128: Consider adding clarification about why getResponseHeaders() is used.

The documentation now uses getResponseHeaders() to set cache headers in the middleware example, but doesn't explain why this approach is necessary instead of directly accessing result.response.headers. Based on the PR objective, result.response may be undefined in certain contexts. Adding a brief comment or explanation would help developers understand the reasoning and avoid similar pitfalls.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between be4764c and 335443d.

📒 Files selected for processing (1)
  • docs/start/framework/react/guide/isr.md
🧰 Additional context used
📓 Path-based instructions (1)
docs/**/*.{md,mdx}

📄 CodeRabbit inference engine (AGENTS.md)

Use relative links to docs/ folder format (e.g., ./guide/data-loading) for internal documentation references

Files:

  • docs/start/framework/react/guide/isr.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Preview
🔇 Additional comments (1)
docs/start/framework/react/guide/isr.md (1)

115-115: Update the etagMiddleware example for consistency with the new pattern.

The cacheMiddleware example now uses getResponseHeaders() to set headers, but the etagMiddleware example at line 351 still uses result.response.headers.set(). For consistency and to avoid confusion, the etagMiddleware example should be updated to use the same getResponseHeaders() approach.

Can you confirm whether the etagMiddleware example (line 339-354) should also be updated to use getResponseHeaders() instead of result.response.headers? If so, please update it to:

 const etagMiddleware = createMiddleware().server(async ({ next }) => {
   const result = await next()

   // Generate ETag from response content
   const etag = crypto
     .createHash('md5')
     .update(JSON.stringify(result.data))
     .digest('hex')

-  result.response.headers.set('ETag', `"${etag}"`)
+  const headers = getResponseHeaders()
+  headers.set('ETag', `"${etag}"`)

   return result
 })

(Note: You may also need to add import { getResponseHeaders } from '@tanstack/react-start/server' at the top of that example if not already imported.)

Also applies to: 121-125

@LadyBluenotes

Copy link
Copy Markdown
Member

Thanks for tracking this down, and sorry this sat for so long. The middleware runtime has changed since this was opened: current main now guarantees response: Response on request middleware next() results, and the focused Start server regression mutates result.response.headers and verifies that the header reaches the final response. That behavior landed through #7497, building on #5517.

The existing ISR example is valid again. Switching only this block to getResponseHeaders() would also leave the ETag and cache-monitoring examples on the same page using result.response.headers, so I think we can close this as no longer necessary. The reproduction was useful in exposing the original mismatch, so thank you for that!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Everything documentation related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants