Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: subscription route not applying transformer to emitted data #14

Open
firemuzzy opened this issue Nov 20, 2023 · 0 comments
Open

Bug: subscription route not applying transformer to emitted data #14

firemuzzy opened this issue Nov 20, 2023 · 0 comments

Comments

@firemuzzy
Copy link

If you have trpc configured with a custom transformer, the transformer is not called on emitted data from the router. The receiving end calls deserialize resulting un undefined edited data from the subscription.

The example below uses superjson and the onData of the subscription will return undefined because the receiving end is expecting the data to be serialized with the provided transformer.

// background
const t = initTRPC.create({ transformer: superjson });

const appRouter = t.router({
  echoSubscription: t.procedure
    .input(z.object({ payload: z.string(), date: z.date() }))
    .subscription(({ input }) =>
      observable<typeof input>((emit) => {
        emit.next(input);
      }),
    ),
});

// content script
trpc.nestedRouter.echoSubscription.subscribe(
  { payload: 'subscription1', date: date1 },
  {
    onData: (data) => {
      // data will be undefined here
    }
  }
)
@firemuzzy firemuzzy changed the title Bug: subscription route not applying transformer to edited data Bug: subscription route not applying transformer to emited data Nov 20, 2023
firemuzzy added a commit to LabCo/trpc-chrome that referenced this issue Nov 20, 2023
@firemuzzy firemuzzy changed the title Bug: subscription route not applying transformer to emited data Bug: subscription route not applying transformer to emitted data Nov 20, 2023
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

No branches or pull requests

1 participant