Skip to content

[DevTools] Obscure error "contextMap[utilName] is not a function" when passing certain context to the router  #909

@AkshayPathak

Description

@AkshayPathak

Describe the bug

When passing a context to the Router with the trpc.useUtils() hook causes an obscure error.

function MyApp() {
  const utils = trpc.useUtils();
  return <RouterProvider router={router} context={{ trpcClient: utils }} />;
}

The error is Uncaught TypeError: contextMap[utilName] is not a function. It occurs in the <Explorer /> component in the DevTools.

I have found a temporary workaround by attempting to get the context panel to be in the collapsed state. As soon as I expand it, it throws this error.

In the stackblitz, I am unable to collapse the context section by default. However, it throws the error regardless.

From my testing, I am still unsure what types of items passed to the context field in the RouterProvider are causing the error. I have tried strings, numbers, variables from useState without it causing this error.

Your Example Website or App

https://stackblitz.com/edit/github-4ycrcx?file=client%2Fmain.tsx

Steps to Reproduce the Bug or Issue

  1. Go to Stackblitz above
  2. See an error concurring
  3. Change the trpcClient on line 42 to a string or number or any other variable and notice that it works

Expected behavior

The DevTools should not throw an error when it sees the trpc utils.

Screenshots or Videos

No response

Platform

  • OS: Linux
  • Browser: Chrome
  • Version: Latest

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions