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

[Violation] 'message' handler took 215ms #6832

Closed
jamalsoueidan opened this issue Aug 10, 2024 · 2 comments
Closed

[Violation] 'message' handler took 215ms #6832

jamalsoueidan opened this issue Aug 10, 2024 · 2 comments

Comments

@jamalsoueidan
Copy link

How frequently does the bug occur?

Always

Description

I call a function in atlas mongodb, and then I receive these errors, if I also wait for message in the chat, I also receive these kind of errors right before i receive the messages, sometime the app continue to work, but sometime suddently it freeze.

Stacktrace & log output

(17) [Violation] 'setTimeout' handler took <N>ms
realm-js-wasm.mjs:8 [Violation] 'message' handler took 215ms
Scrollbar.tsx:40 [Violation] Handling of 'wheel' input event was delayed for 4383 ms due to main thread being busy. Consider marking event handler as 'passive' to make the page more responsive.
Scrollbar.tsx:40 [Violation] Handling of 'wheel' input event was delayed for 4383 ms due to main thread being busy. Consider marking event handler as 'passive' to make the page more responsive.
realm-js-wasm.mjs:8 [Violation] 'message' handler took 604ms


### Can you reproduce the bug?

Always

### Reproduction Steps

Very simple setup, nothing fancy

```js
import { Box, Input, Loader, Stack } from "@mantine/core";
import { getHotkeyHandler } from "@mantine/hooks";
import { useUser } from "@realm/react";
import { useEffect, useRef, useState } from "react";
import { useMessages } from "../sources/useMessages";
import { MessageImage } from "./messages-types/MessageImage";
import { MessageText } from "./messages-types/MessageText";
import { MessageUnknown } from "./messages-types/MessageUnknown";

export function Messages({ conversation }: { conversation: string }) {
  const user = useUser();

  const [value, setValue] = useState("");
  const [sendingMessages, setSendingMessages] = useState<string[]>([]);
  const { messages } = useMessages({
    conversation,
  });
  const previousMessageLength = useRef(messages.length);
  const messagesEndRef = useRef<null | HTMLDivElement>(null);

  const scrollToBottom = () => {
    messagesEndRef.current?.scrollIntoView({ behavior: "instant" });
  };

  useEffect(() => {
    setTimeout(() => {
      scrollToBottom();
    }, 250);
  }, [messages]);

  useEffect(() => {
    setTimeout(() => {
      scrollToBottom();
    }, 250);
  }, []);

  const handleSubmit = () => {
    const currentValue = value;
    previousMessageLength.current = messages.length;
    setValue("");

    // Add to sending messages list
    setSendingMessages((prev) => [...prev, currentValue]);

    user.functions["func-send-messages"]({
      business_phone_number_id: "364826260",
      messaging_product: "whatsapp",
      recipient_type: "individual",
      to: "0012331317428",
      type: "text",
      text: {
        preview_url: true,
        body: currentValue,
      },
    }).finally(() => {
      setSendingMessages((prev) => prev.filter((msg) => msg !== currentValue));
    });
  };

  return (
    <>
      <div
        style={{
          overflowX: "hidden",
          overflowY: "scroll",
          backgroundColor: "gray",
          height: "calc(100% - 70px)",
          padding: "20px",
        }}
      >
        <Stack gap="5px">
          {messages.map((msg) => {
            if (msg.type === "text") {
              return <MessageText msg={msg} key={msg._id as any} />;
            } else if (msg.type === "image") {
              return <MessageImage msg={msg} key={msg._id as any} />;
            } else {
              return <MessageUnknown msg={msg} key={msg._id as any} />;
            }
          })}
        </Stack>
        <div ref={messagesEndRef} />
      </div>
      <Box p="md">
        <Input
          size="md"
          placeholder="Type a message"
          radius="md"
          autoFocus
          value={value}
          rightSection={
            sendingMessages.length ? <Loader color="blue" size="sm" /> : <></>
          }
          onChange={(e) => setValue(e.target.value)}
          onKeyDown={getHotkeyHandler([["Enter", handleSubmit]])}
        />
      </Box>
    </>
  );
}

Version

12.0.0-browser.2

What services are you using?

Atlas App Services: Functions or GraphQL or DataAPI etc

Are you using encryption?

No

Platform OS and version(s)

Windows

Build environment

No response

Cocoapods version

No response

Copy link

sync-by-unito bot commented Aug 10, 2024

➤ PM Bot commented:

Jira ticket: RJS-2881

@jamalsoueidan
Copy link
Author

jamalsoueidan commented Aug 10, 2024

The project was using the old ReactDOM.render, so I changed it to createRoot. and now it works.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant