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

realtime is not emitting DELETE events (but INSERT or UPDATE is working) #1154

Closed
topTOP-Dev opened this issue Sep 13, 2024 · 1 comment
Closed
Labels
bug Something isn't working

Comments

@topTOP-Dev
Copy link

topTOP-Dev commented Sep 13, 2024

Bug report

Describe the bug

I'm using the realtime for crud operation.

useEffect(() => {
    // Define an async function for the subscription
    const subscribeToChannel = async () => {
      const subscription = supabase
        .channel(channelRoom)
        .on(
          "postgres_changes",
          {
            event: "*",
            schema: "public",
            table: tableName,
            filter: `dof=eq.${selectedDate.format("YYYY-MM-DD")}`, // Corrected the date formatting
          },
          (payload: any) => {
            console.log(payload);
            switch (payload.eventType) {
              case "UPDATE":
                setAtcFlights((prev: Flight[]) =>
                  prev.map((flight: Flight) =>
                    flight.id === payload.new.id ? payload.new : flight
                  )
                );
                break;
              case "DELETE":
                // setAtcFlights((prev: Flight[]) => {
                //   const updatedFlights = prev.filter(
                //     (flight: Flight) => flight.id !== payload.old.id
                //   );
                //   return updatedFlights;
                // });
                // Optionally, refetch the data to ensure consistency
                fetchFlightList();
                break;
              case "INSERT":
                if (
                  payload.new.airport === airport.toUpperCase() &&
                  payload.new.dof === formattedDate
                ) {
                  setAtcFlights((prev: Flight[]) => [...prev, payload.new]);
                }
                break;
              default:
                break;
            }
          }
        )
        .subscribe();

      // Cleanup function to remove the subscription
      return () => {
        supabase.removeChannel(subscription);
      };
    };

    // Call the async function
    subscribeToChannel();

    // Dependencies for useEffect
  }, [
    supabase,
    tableName,
    formattedDate,
    airport,
    atcFlights,
    setAtcFlights,
    channelRoom,
  ]);

When I run in local development mode, the delete event type is emitted normally. But when I deploy to the production. Such delete event type is not emitted. But the data is deleted from my database as normal.

Screenshots

This is in development.
Screenshot 2567-09-13 at 22 37 33

This is in production. (There are only INSERT or UPDATE event type. The DELETE is not emitted.)
Screenshot 2567-09-13 at 22 38 00

System information

  • OS: [e.g. macOS]
  • Browser (if applies) [e.g. Microsoft Edge]
  • Version of supabase-js: [e.g. 2.45.4]
  • Version of Node.js: [e.g. 22.8.0]
@topTOP-Dev
Copy link
Author

Thanks a lot. I found out that the delete event type does not contain my dof's value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant