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

Fixed bug where unauthenticated users would get subscription errors in the console. #8833

Merged
merged 10 commits into from
Aug 14, 2024

Conversation

burtonator
Copy link
Collaborator

Link to Issue

Closes:

Description of Changes

  • Moves the subscription toggle and all the associated logic of it to a dedicated class

"How We Fixed It"

Test Plan

  • Load a thread when the user is not logged in.
  • Make sure there is at least one comment.
  • Then check logs and make sure theres no error.
  • Make sure toggling of subscriptions works properly when on the thread page (and it has comments)

Deployment Plan

Other Considerations

@burtonator burtonator self-assigned this Aug 12, 2024
@burtonator burtonator marked this pull request as ready for review August 12, 2024 23:14
@masvelio
Copy link
Contributor

masvelio commented Aug 13, 2024

The pattern we usually use it to pass enabled flag to the react query. I think in this case it might work as well

export function useCommentSubscriptionsQuery({
  apiEnabled,
}: {
  apiEnabled: boolean;
}) {
  return trpc.subscription.getCommentSubscriptions.useQuery(
    {},
    { enabled: apiEnabled },
  );
}

@burtonator burtonator changed the title subscriptions for unauthorized Fixed bug where unauthenticated users would get subscription errors in the console. Aug 13, 2024
Copy link
Contributor

@masvelio masvelio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

original bug is not reproducible for me anymore but I am getting different errors now

image

[09:26:44.874] ERROR (index.ts): INTERNAL_SERVER_ERROR: [ZodError] subscription.getCommentSubscriptions: [
  {
    "code": "invalid_type",
    "expected": "object",
    "received": "null",
    "path": [
      0,
      "Comment",
      "Thread"
    ],
    "message": "Expected object, received null"
  }
] 
    err: {
      "type": "ZodError",
      "message": "[\n  {\n    \"code\": \"invalid_type\",\n    \"expected\": \"object\",\n    \"received\": \"null\",\n    \"path\": [\n      0,\n      \"Comment\",\n      \"Thread\"\n    ],\n    \"message\": \"Expected object, received null\"\n  }\n]",
      "stack":
          ZodError: [
            {
              "code": "invalid_type",
              "expected": "object",
              "received": "null",
              "path": [
                0,
                "Comment",
                "Thread"
              ],
              "message": "Expected object, received null"
            }
          ]
              at get error [as error] (file:///Users/marcin/Desktop/Projects/commonwealth/node_modules/.pnpm/[email protected]/node_modules/zod/lib/index.mjs:587:31)
              at ZodArray.parseAsync (file:///Users/marcin/Desktop/Projects/commonwealth/node_modules/.pnpm/[email protected]/node_modules/zod/lib/index.mjs:715:22)
              at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
              at async outputMiddleware (file:///Users/marcin/Desktop/Projects/commonwealth/node_modules/.pnpm/@[email protected]/node_modules/@trpc/server/dist/index.mjs:308:26)
              at async callRecursive (file:///Users/marcin/Desktop/Projects/commonwealth/node_modules/.pnpm/@[email protected]/node_modules/@trpc/server/dist/index.mjs:451:32)
              at async callRecursive (file:///Users/marcin/Desktop/Projects/commonwealth/node_modules/.pnpm/@[email protected]/node_modules/@trpc/server/dist/index.mjs:451:32)
              at async resolve (file:///Users/marcin/Desktop/Projects/commonwealth/node_modules/.pnpm/@[email protected]/node_modules/@trpc/server/dist/index.mjs:481:24)
              at async inputToProcedureCall (file:///Users/marcin/Desktop/Projects/commonwealth/node_modules/.pnpm/@[email protected]/node_modules/@trpc/server/dist/resolveHTTPResponse-2fc435bb.mjs:46:22)
              at async Promise.all (index 0)
              at async resolveHTTPResponse (file:///Users/marcin/Desktop/Projects/commonwealth/node_modules/.pnpm/@[email protected]/node_modules/@trpc/server/dist/resolveHTTPResponse-2fc435bb.mjs:182:37)
      "aggregateErrors": [
        {
          "type": "Object",
          "message": "Expected object, received null",
          "stack":
              
          "code": "invalid_type",
          "expected": "object",
          "received": "null",
          "path": [
            0,
            "Comment",
            "Thread"
          ]
        }
      ],
      "issues": [
        {
          "code": "invalid_type",
          "expected": "object",
          "received": "null",
          "path": [
            0,
            "Comment",
            "Thread"
          ],
          "message": "Expected object, received null"
        }
      ],
      "name": "ZodError"
    }

lets fix this in another pr and this is g2g

@burtonator burtonator merged commit 7cebf7f into master Aug 14, 2024
9 checks passed
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

Successfully merging this pull request may close these issues.

3 participants