Skip to content

HMR in Next.js monorepos: procedures use stale code at runtime when workspace changes are made #1346

@inducingchaos

Description

@inducingchaos

Environment

Next.js: 16.0.8
oRPC: 1.12.2
pnpm: 10.20.0
Node.js 22.20.0

Reproduction

https://github.com/inducingchaos/code-reproductions/tree/orpc-nextjs-monorepo-hmr-staleness

Describe the bug

See the reproduction README for more details.

Basically, whenever you make changes on the backend, Turbopack does not recompile them and you end up with your dev server running code that doesn't physically exist in your codebase.

What I've figured out (disclaimer: I don't know much about bundlers or how object references work):

I found a lot more nuanced details while testing, but how the project constructs the dependency/import graph really affects it (e.g., at some point saving the router file logged v2 at the module level but not in the handlers, as well as updating the Next.js API endpoints would trigger the handler code to be successfully updated). Because of this, it's really hard to provide concrete facts about the issue.

I've been trying to resolve this since Tuesday evening with Opus 4.5 and finally got it working in my main app using a Proxy instance (thanks to the idea from https://github.com/unnoq/orpc/discussions/744), but wasn't able to get this solution to work in the repro.

Any ideas?

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingupstreamIssue caused by upstream dependency or external repository

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions