Skip to content

fix(server): return correct context from middleware next#245

Merged
dinwwwh merged 2 commits intomainfrom
fix/server/incorrect-context-return-by-next-in-middleware
Mar 15, 2025
Merged

fix(server): return correct context from middleware next#245
dinwwwh merged 2 commits intomainfrom
fix/server/incorrect-context-return-by-next-in-middleware

Conversation

@dinwwwh
Copy link
Copy Markdown
Member

@dinwwwh dinwwwh commented Mar 15, 2025

Recent changes not restrict middleware out context match with in context, so we need reflect it in runtime.

Summary by CodeRabbit

Summary by CodeRabbit

  • Tests
    • Enhanced middleware test cases with additional assertions to verify that each middleware component produces the expected output and context.
  • Refactor
    • Improved internal context management during middleware execution for more consistent state propagation and simplified structure.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 15, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
orpc ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 15, 2025 2:45am

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 15, 2025

Walkthrough

This update enhances the middleware verification tests and refines the context merging in the procedure client's execution. New assertions in the tests confirm the output and context from multiple middleware functions. In the main procedure client, the context is now extracted as a new variable and merged via a helper function, streamlining the middleware execution logic. The related import statement has also been updated.

Changes

File(s) Change Summary
packages/.../procedure-client.test.ts Added assertions in tests to verify the resolved output and context for middleware functions: preMid1, preMid2, postMid1, postMid2, and handler.
packages/.../procedure-client.ts Modified executeProcedureInternal to extract a new midContext and merge it with the current context via mergeCurrentContext. Updated the import accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant C as Caller
    participant PC as ProcedureClient
    participant MC as mergeCurrentContext
    participant M as Middleware
    participant H as Handler

    C->>PC: executeProcedureInternal(options)
    PC->>PC: Extract midContext from options
    PC->>MC: mergeCurrentContext(currentContext, midContext)
    MC-->>PC: merged context
    PC->>M: Execute pre-middleware functions
    M-->>PC: Return pre-middleware result
    PC->>H: Execute procedure handler with merged context
    H-->>PC: Handler result
    PC->>M: Execute post-middleware functions
    M-->>PC: Return post-middleware result
    PC-->>C: Return final result
Loading

Poem

I'm a rabbit in the codefield, so light and free,
Hopping through context changes with glee.
Middleware steps now clear and bright,
Merging contexts makes my heart delight.
In every test, I bounce with cheer—
Code improvements make this bunny's day clear!
🐰💻

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

 ERR_PNPM_OPTIONAL_DEPS_REQUIRE_PROD_DEPS  Optional dependencies cannot be installed without production dependencies


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d2b83e4 and 8ba1428.

📒 Files selected for processing (1)
  • packages/server/src/procedure-client.test.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/server/src/procedure-client.test.ts

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 15, 2025

Open in Stackblitz

More templates

@orpc/client

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

@orpc/contract

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

@orpc/openapi

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

@orpc/openapi-client

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

@orpc/react-query

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

@orpc/server

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

@orpc/shared

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

@orpc/solid-query

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

@orpc/standard-server

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

@orpc/standard-server-fetch

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

@orpc/svelte-query

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

@orpc/vue-colada

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

@orpc/vue-query

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

@orpc/standard-server-node

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

@orpc/zod

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

commit: 8ba1428

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@dinwwwh dinwwwh merged commit 5d6030b into main Mar 15, 2025
8 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