Skip to content

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

@firemuzzy

Description

@firemuzzy

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
    }
  }
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions