Skip to content

fix: handle custom Request objects that cannot be cloned - #574

Merged
samuelstroschein merged 3 commits into
generaltranslation:mainfrom
iktakahiro:fix/issue-573-request-clone-error
Jan 7, 2026
Merged

samuelstroschein merged 3 commits into
generaltranslation:mainfrom
iktakahiro:fix/issue-573-request-clone-error

Conversation

@iktakahiro

@iktakahiro iktakahiro commented Jan 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Fix runtime error "Cannot read private member #state" when using paraglideMiddleware with TanStack Start 1.143+
  • When URL strategy is not used, try to clone the request but fall back to the original request if cloning fails
  • Maintains backwards compatibility with NextJS while supporting TanStack Start's custom Request implementation

Problem

TanStack Start 1.143+ uses a custom Request implementation with private fields (#state). When paraglide-js tries to clone the request using new Request(request), Node's undici Request constructor cannot access these private fields, causing the error:

Cannot read private member #state from an object whose class did not declare it

Solution

Instead of unconditionally cloning the request when URL strategy is not used, we now:

  1. Try to clone the request with new Request(request)
  2. If cloning fails (throws an error), fall back to using the original request

This approach:

Test plan

  • Added test case for custom Request objects that cannot be cloned
  • Existing middleware tests pass (21 tests)

Fixes #573


Note

Adds defensive request cloning in paraglideMiddleware to support runtimes with custom Request wrappers.

  • When strategy excludes url, attempt new Request(request) and fall back to the original request on error; url strategy de-localization remains unchanged
  • New test verifies fallback with a custom, non-clonable Request (TanStack Start scenario)
  • Adds changeset entry and ignores examples/tanstack-start/project.inlang/cache

Written by Cursor Bugbot for commit b31a63e. This will update automatically on new commits. Configure here.

Some frameworks like TanStack Start 1.143+ use custom Request implementations
with private fields (e.g., #state) that cannot be cloned using
`new Request(request)`. This causes a runtime error:
"Cannot read private member #state from an object whose class did not declare it"

When URL strategy is not used, the middleware now tries to clone the request
but falls back to using the original request if cloning fails. This maintains
backwards compatibility with frameworks like NextJS that require a new Request
object while also supporting frameworks with custom Request implementations.

Fixes generaltranslation#573

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@samuelstroschein

Copy link
Copy Markdown
Contributor

@iktakahiro i'll merge this tomorrow. I am boarding a plane right now (and learned before that's it's a bad idea to merge a patch right before being offline for 18 hours)

@iktakahiro

Copy link
Copy Markdown
Contributor Author

@samuelstroschein Have a safe flight!

@samuelstroschein
samuelstroschein merged commit f76a97c into generaltranslation:main Jan 7, 2026
1 check passed
@samuelstroschein

Copy link
Copy Markdown
Contributor

@iktakahiro Thanks for the PR. Released as 2.7.2

@iktakahiro
iktakahiro deleted the fix/issue-573-request-clone-error branch January 7, 2026 07:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: Cannot read private member #state when using paraglideMiddleware with TanStack Start 1.145+

2 participants