Skip to content

fix(client): match subclasses in ORPCError cross-context instanceof check - #1762

Merged
dinwwwh merged 1 commit into
middleapi:mainfrom
dinwwwh:fix/client/match-subclasses-in-ORPCError-cross-context-instanceof-check
Aug 2, 2026
Merged

fix(client): match subclasses in ORPCError cross-context instanceof check#1762
dinwwwh merged 1 commit into
middleapi:mainfrom
dinwwwh:fix/client/match-subclasses-in-ORPCError-cross-context-instanceof-check

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Aug 2, 2026

Copy link
Copy Markdown
Member

The cross-context instanceof ORPCError workaround only checked an instance's direct constructor against the registered constructor set, so instances of classes extending an ORPCError from another dependency graph (e.g. Next.js Optimized SSR contexts) failed the check. Symbol.hasInstance now walks the instance's whole prototype chain, so such subclass instances are recognized as ORPCError too.

Fixes

  • Subclasses of a foreign-context ORPCError now pass instanceof ORPCError; previously only direct instances matched.
  • Same-context behavior is unchanged — the default instanceof fallback and the extended-class guard are untouched, and only registered ORPCError constructors can match, so no false positives.

Testing

  • New getConstructors helper in @orpc/shared is covered for primitives, built-ins, inheritance chains, null-prototype objects, and laziness.
  • New test simulates a foreign dependency graph by registering an unrelated class in the global constructor set, verifying both it and its subclass pass instanceof ORPCError, and that they stop matching once deregistered.

@vercel

vercel Bot commented Aug 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
orpc Ready Ready Preview Aug 2, 2026 7:59am

@pkg-pr-new

pkg-pr-new Bot commented Aug 2, 2026

Copy link
Copy Markdown
More templates

@orpc/ai-sdk

npm i https://pkg.pr.new/@orpc/ai-sdk@1762

@orpc/arktype

npm i https://pkg.pr.new/@orpc/arktype@1762

@orpc/bun

npm i https://pkg.pr.new/@orpc/bun@1762

@orpc/client

npm i https://pkg.pr.new/@orpc/client@1762

@orpc/cloudflare

npm i https://pkg.pr.new/@orpc/cloudflare@1762

@orpc/contract

npm i https://pkg.pr.new/@orpc/contract@1762

@orpc/experimental-effect

npm i https://pkg.pr.new/@orpc/experimental-effect@1762

@orpc/evlog

npm i https://pkg.pr.new/@orpc/evlog@1762

@orpc/json-schema

npm i https://pkg.pr.new/@orpc/json-schema@1762

@orpc/nest

npm i https://pkg.pr.new/@orpc/nest@1762

@orpc/next

npm i https://pkg.pr.new/@orpc/next@1762

@orpc/openapi

npm i https://pkg.pr.new/@orpc/openapi@1762

@orpc/opentelemetry

npm i https://pkg.pr.new/@orpc/opentelemetry@1762

@orpc/pinia-colada

npm i https://pkg.pr.new/@orpc/pinia-colada@1762

@orpc/pino

npm i https://pkg.pr.new/@orpc/pino@1762

@orpc/publisher

npm i https://pkg.pr.new/@orpc/publisher@1762

@orpc/ratelimit

npm i https://pkg.pr.new/@orpc/ratelimit@1762

@orpc/server

npm i https://pkg.pr.new/@orpc/server@1762

@orpc/shared

npm i https://pkg.pr.new/@orpc/shared@1762

@orpc/swr

npm i https://pkg.pr.new/@orpc/swr@1762

@orpc/tanstack-query

npm i https://pkg.pr.new/@orpc/tanstack-query@1762

@orpc/trpc

npm i https://pkg.pr.new/@orpc/trpc@1762

@orpc/valibot

npm i https://pkg.pr.new/@orpc/valibot@1762

@orpc/zod

npm i https://pkg.pr.new/@orpc/zod@1762

commit: 693b71e

@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes — a targeted fix for the ORPCError cross-context instanceof check so subclass instances from foreign dependency graphs are recognized:

  • New getConstructors() generator in @orpc/shared that walks the full prototype chain, yielding each constructor
  • Updated Symbol.hasInstance to iterate the full chain instead of checking only the direct constructor
  • Clean test coverage — the new cross-context test would fail without the fix (subclass ExtendedCrossContextORPCError would not match), and the getConstructors tests cover primitives, built-ins, inheritance chains, null-prototype objects, skipped levels, and laziness

All tests, type checks, and lint pass.

Pullfrog  | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@codspeed-hq

codspeed-hq Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 12.55%

❌ 1 regressed benchmark
✅ 24 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
plain 146.5 µs 167.5 µs -12.55%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing dinwwwh:fix/client/match-subclasses-in-ORPCError-cross-context-instanceof-check (693b71e) with main (11f1ac8)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (a8d4afc) during the generation of this report, so 11f1ac8 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@dinwwwh
dinwwwh merged commit 4b86526 into middleapi:main Aug 2, 2026
12 of 13 checks passed
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.

1 participant