Title: [React-Router Framework]: Add Cloudflare support · Issue #17334 · getsentry/sentry-javascript · GitHub
Open Graph Title: [React-Router Framework]: Add Cloudflare support · Issue #17334 · getsentry/sentry-javascript
X Title: [React-Router Framework]: Add Cloudflare support · Issue #17334 · getsentry/sentry-javascript
Description: Description Deploying @sentry/react-router to Cloudflare Workers is currently not supported out of the box. However, this issue provides a workaround for making it work. Support renderToReadableStream The react-router SDK is currently us...
Open Graph Description: Description Deploying @sentry/react-router to Cloudflare Workers is currently not supported out of the box. However, this issue provides a workaround for making it work. Support renderToReadableStr...
X Description: Description Deploying @sentry/react-router to Cloudflare Workers is currently not supported out of the box. However, this issue provides a workaround for making it work. Support renderToReadableStr...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/17334
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[React-Router Framework]: Add Cloudflare support","articleBody":"### Description\n\nDeploying `@sentry/react-router` to Cloudflare Workers is currently not supported out of the box. However, this issue provides a workaround for making it work.\n\n### Support `renderToReadableStream`\n\nThe react-router SDK is currently using [`renderToPipeableStream`](https://github.com/getsentry/sentry-javascript/blob/ac57eb17ad3db93f7d24335e39d85211cb1e068f/packages/react-router/src/server/createSentryHandleRequest.tsx#L96) which is a Node-only API. For react-router to be able to inject the HTML meta tags, this code needs to be adapted to use `renderToReadableStream`.\n\n### Current Workaround\n\nWrap the handler with `withSentry` from `@sentry/cloudflare`:\n\n```ts\n// in entry.worker.ts\nimport type { unstable_InitialContext } from \"react-router\";\nimport { createRequestHandler, unstable_createContext } from \"react-router\";\nimport * as build from \"virtual:react-router/server-build\";\nimport * as Sentry from \"@sentry/cloudflare\";\n\nconst CloudflareContext = unstable_createContext\u003c{\n env: Cloudflare.Env;\n ctx: ExecutionContext;\n cf?: RequestInitCfProperties;\n}>();\n\nexport default Sentry.withSentry(\n () => ({ /* Sentry config options */ }),\n {\n async fetch(request: Request, env: Cloudflare.Env, ctx: ExecutionContext) {\n const context: unstable_InitialContext = new Map();\n context.set(CloudflareContext, { env, ctx, cf: request.cf });\n return await handler(request, context);\n },\n } satisfies ExportedHandler\u003cCloudflare.Env>,\n);\n```\n\nNow, create a function to include the HTML meta tags (like [here](https://github.com/getsentry/sentry-javascript/blob/ac57eb17ad3db93f7d24335e39d85211cb1e068f/packages/react-router/src/server/wrapSentryHandleRequest.ts#L80)) and inject them into the returned body:\n```ts\n// in app/entry.server.tsx\nimport { renderToReadableStream } from \"react-dom/server\";\nimport { getTraceMetaTags, getTraceData, getClient } from \"@sentry/core\";\n\nfunction getWebMetaTagTransformer(): TransformStream\u003cUint8Array, Uint8Array> {\n const headClosingTag = \"\u003c/head>\";\n\n const decoder = new TextDecoder();\n const encoder = new TextEncoder();\n\n return new TransformStream({\n transform(chunk, controller) {\n const html = decoder.decode(chunk);\n\n if (html.includes(headClosingTag)) {\n const modifiedHtml = html.replace(\n headClosingTag,\n `${getTraceMetaTags()}${headClosingTag}`,\n );\n controller.enqueue(encoder.encode(modifiedHtml));\n return;\n }\n controller.enqueue(chunk);\n },\n });\n}\n\nexport default async function handleRequest(/* .... */){\n // ...\n\n const body = await renderToReadableStream(/* ... */)\n\n const sentryTransformer = getWebMetaTagTransformer();\n const transformedBody = body.pipeThrough(sentryTransformer);\n \n return new Response(transformedBody, {\n headers: responseHeaders,\n status: responseStatusCode,\n });\n}\n```\n\n\n","author":{"url":"https://github.com/s1gr1d","@type":"Person","name":"s1gr1d"},"datePublished":"2025-08-06T09:44:10Z","url":"https://github.com/getsentry/sentry-javascript/issues/17334"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8f8d8e10-011e-5573-7d9c-b68f4d1f1a88 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 96B0:33251C:7118A0:9DF4F4:6B05C404 |
| html-safe-nonce | 23d79002859e1c6b3a991732edd3214458fe105f8724ed80dc939a8e837704ff |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NkIwOjMzMjUxQzo3MTE4QTA6OURGNEY0OjZCMDVDNDA0IiwidmlzaXRvcl9pZCI6IjM1NjE0NDkzNzU0MTI4OTY3NzIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | a598948ce54776759feb72448b2a64d1c1c3f6ca7d62c8dbdb5c3f13b6e4a47b |
| hovercard-subject-tag | issue:3296017063 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/17334/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ab5210dddf08bec5824ac67a17f07e92f9f1c2968002c213911d9641645377cd/getsentry/sentry-javascript/issues/17334 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ab5210dddf08bec5824ac67a17f07e92f9f1c2968002c213911d9641645377cd/getsentry/sentry-javascript/issues/17334 |
| og:image:alt | Description Deploying @sentry/react-router to Cloudflare Workers is currently not supported out of the box. However, this issue provides a workaround for making it work. Support renderToReadableStr... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | s1gr1d |
| hostname | github.com |
| expected-hostname | github.com |
| None | 13b1c5df76a26b2d8420784ae7f9fb9c438fc6cb0c95a689d26fb49879d8e556 |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3328572 |
| octolytics-dimension-repository_nwo | getsentry/sentry-javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3328572 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-javascript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | bcf1e3e7f14567fd89b0218ee06dd0aad8f1d288 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width