Skip to content

fix(client): move global ORPCError constructors registration to static block for better bundler compatibility#1574

Merged
dinwwwh merged 11 commits into
middleapi:mainfrom
dinwwwh:main
Jun 5, 2026
Merged

fix(client): move global ORPCError constructors registration to static block for better bundler compatibility#1574
dinwwwh merged 11 commits into
middleapi:mainfrom
dinwwwh:main

Conversation

@dinwwwh
Copy link
Copy Markdown
Member

@dinwwwh dinwwwh commented Jun 5, 2026

Summary by CodeRabbit

  • Refactor
    • Improved internal error handling architecture for better code organization and maintainability. No user-facing changes.

@dinwwwh dinwwwh requested a review from Copilot June 5, 2026 03:33
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Jun 5, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 5, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e1ae6aa7-28ee-43d0-9cae-e1d57ed42775

📥 Commits

Reviewing files that changed from the base of the PR and between e666e40 and 4abbd0c.

📒 Files selected for processing (1)
  • packages/client/src/error.ts

📝 Walkthrough

Walkthrough

Constructor registration logic for cross-dependency-graph instanceof support is moved from module-load time into a static {} block on the ORPCError class. The shared WeakSet on globalThis is still initialized the same way, but now as part of class definition rather than module execution.

Changes

Error Constructor Static Initialization

Layer / File(s) Summary
ORPCError constructor registration refactor
packages/client/src/error.ts
Module-level globalORPCErrorConstructors setup and ORPCError registration are relocated into a static {} block within the class definition, consolidating symbol creation, WeakSet initialization on globalThis, and constructor registration while removing the prior module-level registration call.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • middleapi/orpc#340: Both PRs modify packages/client/src/error.ts's ORPCError implementation—this PR refactors constructor registration into a static {} initializer, while the related PR removes deprecated JSON methods and switches to updated error builders.
  • middleapi/orpc#972: Both PRs enhance packages/client/src/error.ts to implement global ORPCError constructor registry and cross-graph instanceof support via similar WeakSet and Symbol.for patterns.

Suggested labels

size:L

Poem

🐰 A hoppy refactor hops along,
Static blocks make init strong!
Constructors dance in class repose,
No more module-load verbose—
Cleaner code from whisker to toe! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: moving ORPCError constructors registration from module-level to a static block, which addresses bundler compatibility issues. The title is specific, concise, and directly reflects the primary modification.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request moves the registration of ORPCError in globalORPCErrorConstructors into a static initialization block inside the ORPCError class to prevent bundlers from tree-shaking it when "sideEffects": false is configured. The reviewer suggests keeping the initialization of globalORPCErrorConstructors as a module-level const instead of a mutable let variable, keeping the static block focused solely on registering the class.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread packages/client/src/error.ts
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates @orpc/client’s ORPCError global-constructor registration so it runs inside the ORPCError class definition (via a static {} initialization block) rather than as module-level side effects, improving compatibility with tree-shaking bundlers when "sideEffects": false.

Changes:

  • Moved global WeakSet registration (via Symbol.for + globalThis) into ORPCError’s static {} block.
  • Removed module-level registration statements and replaced them with a module-scoped let assigned during class initialization.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

@pullfrog pullfrog Bot left a comment

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 — moves the global ORPCError constructor registration from module-level into a static {} block so that bundlers with "sideEffects": false cannot tree-shake the registration away.

  • Move WeakSet init and .add(ORPCError) into static {} — the side-effect is now bound to the class definition, preventing tree-shaking while keeping identical runtime behavior.

Pullfrog  | View workflow run | Using DeepSeek Pro𝕏

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 5, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 5, 2026

More templates

@orpc/ai-sdk

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

@orpc/arktype

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

@orpc/client

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

@orpc/contract

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

@orpc/experimental-durable-iterator

npm i https://pkg.pr.new/@orpc/experimental-durable-iterator@1574

@orpc/hey-api

npm i https://pkg.pr.new/@orpc/hey-api@1574

@orpc/interop

npm i https://pkg.pr.new/@orpc/interop@1574

@orpc/json-schema

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

@orpc/nest

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

@orpc/openapi

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

@orpc/openapi-client

npm i https://pkg.pr.new/@orpc/openapi-client@1574

@orpc/otel

npm i https://pkg.pr.new/@orpc/otel@1574

@orpc/experimental-pino

npm i https://pkg.pr.new/@orpc/experimental-pino@1574

@orpc/experimental-publisher

npm i https://pkg.pr.new/@orpc/experimental-publisher@1574

@orpc/experimental-publisher-durable-object

npm i https://pkg.pr.new/@orpc/experimental-publisher-durable-object@1574

@orpc/experimental-ratelimit

npm i https://pkg.pr.new/@orpc/experimental-ratelimit@1574

@orpc/react

npm i https://pkg.pr.new/@orpc/react@1574

@orpc/react-query

npm i https://pkg.pr.new/@orpc/react-query@1574

@orpc/experimental-react-swr

npm i https://pkg.pr.new/@orpc/experimental-react-swr@1574

@orpc/server

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

@orpc/shared

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

@orpc/solid-query

npm i https://pkg.pr.new/@orpc/solid-query@1574

@orpc/standard-server

npm i https://pkg.pr.new/@orpc/standard-server@1574

@orpc/standard-server-aws-lambda

npm i https://pkg.pr.new/@orpc/standard-server-aws-lambda@1574

@orpc/standard-server-fastify

npm i https://pkg.pr.new/@orpc/standard-server-fastify@1574

@orpc/standard-server-fetch

npm i https://pkg.pr.new/@orpc/standard-server-fetch@1574

@orpc/standard-server-node

npm i https://pkg.pr.new/@orpc/standard-server-node@1574

@orpc/standard-server-peer

npm i https://pkg.pr.new/@orpc/standard-server-peer@1574

@orpc/svelte-query

npm i https://pkg.pr.new/@orpc/svelte-query@1574

@orpc/tanstack-query

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

@orpc/trpc

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

@orpc/valibot

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

@orpc/vue-colada

npm i https://pkg.pr.new/@orpc/vue-colada@1574

@orpc/vue-query

npm i https://pkg.pr.new/@orpc/vue-query@1574

@orpc/zod

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

commit: c252d5b

@dinwwwh dinwwwh merged commit 21703c0 into middleapi:main Jun 5, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants