Skip to content

bug: .useSubscription() results in undefined in data.data of onData() #5900

Closed

Description

@Katli95

Provide environment information

System:
OS: [can provide on explicit request]
CPU: [can provide on explicit request]
Memory: 2.00 GB / 32.00 GB
Shell: /bin/zsh
Binaries:
Node: 20.11.0 - nvm (v20.11.0)
npm: 10.2.4 - same
Browsers:
Chrome: 126.0.6478.127
Safari: 17.5
Firefox: 128.0 (64-bit) --- Used for testing
npmPackages:
@tanstack/react-query: ^5.51.1 => 5.51.1
@trpc/client: ^11.0.0-rc.461 => 11.0.0-rc.461+f178d3fed
@trpc/next: ^11.0.0-rc.461 => 11.0.0-rc.461+f178d3fed
@trpc/react-query: ^11.0.0-rc.461 => 11.0.0-rc.461+f178d3fed
@trpc/server: ^11.0.0-rc.461 => 11.0.0-rc.461+f178d3fed
next: ^14.2.4 => 14.2.4
react: ^18.2.0 => 18.3.1
typescript: 5.2.2 => 5.2.2

Describe the bug

What it says on the tin pretty much, using .useSubscription() results in undefined in data.data of onData().

trpc.x.useSubscription(
    {
        id: item.id,
    },
    {
        onData(payload) {
            console.log("subscription.onData", payload);
        },
    }
);
image

Network tab for proof of data being present:
image

May be related to the use of transformers (devalue using uneval & eval).

Link to reproduction

https://stackblitz.com/edit/github-3c8xbf?file=src%2Fpages%2Findex.tsx

To reproduce

Open the reproduction, npm run dev, open /index, see what's rendered on screen (JSON stringified response of id & data)

Additional information

The code is simplified, I originally had some logic ofc, but for demo purposes I'm just yield-ing directly.

👨‍👧‍👦 Contributing

  • 🙋‍♂️ Yes, I'd be down to file a PR fixing this bug!

Activity

  1. BeBoRE commented on Jul 15, 2024

    @BeBoRE
    Contributor

    You have your transformer setup incorrectly, if you change that it'll work

  2. Katli95 commented on Jul 15, 2024

    @Katli95
    ContributorAuthor

    @BeBoRE Oh, weird, how so? It seems to be working for the regular query, if you check the repro again you can see that it's working for a regular query returning a date object.

    Could you point out exactly what I'm doing wrong? I've been using an equivalent set-up (that is unless I transferred it wrong into the repro) for some time without issue.

  3. BeBoRE commented on Jul 15, 2024

    @BeBoRE
    Contributor

    Idk useSubscription uses the input deserializer instead of the output deserializer (like the other links) to consume the stream, idk if that is a bug

  4. BeBoRE commented on Jul 15, 2024

    @BeBoRE
    Contributor

    Is this intentional @KATT?

    deserialize: transformer.input.deserialize,

    Seems like everywhere else the output transformer is used:

    deserialize: resolvedOpts.transformer.output.deserialize,

    resolvedOpts.transformer.output,

    resolvedOpts.transformer.output,

  5. KATT commented on Jul 15, 2024

    @KATT
    Member

    Looks wrong indeed, nice find

  6. Katli95 commented on Jul 16, 2024

    @Katli95
    ContributorAuthor

    Is this intentional @KATT?

    deserialize: transformer.input.deserialize,

    Seems like everywhere else the output transformer is used:

    ...

    Awesome, yeah, good spot, I'll take a shot at fixing it with a PR!

    Work in Progress Fork

  7. github-actions commented on Jul 17, 2024

    @github-actions
    Contributor

    This issue has been locked because we are very unlikely to see comments on closed issues. If you are running into a similar issue, please create a new issue. Thank you.

  8. locked as resolved and limited conversation to collaborators on Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions