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

PostgresChanges subscription sends wrong tables to subscription after coming back from bring backgrounded #1187

Open
2 tasks
Justinyu1618 opened this issue Nov 5, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Justinyu1618
Copy link

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

I'm using Supabase realtime for postgres_changes in a webview application on mobile. When I background the app, the client does not receive any events. When I re-enter the app before the socket has timed out, I get all of the events that were sent in the interim all at once.

The problem is the new data for a table is sent to every table's callback, not just the callback for that table. This only happens in the scenario when the app is recovering from being backgrounded and receiving events all at once.

To Reproduce

  1. Try to create a supabase client in the browser, subscribed to multiple tables
  2. Go to the app on a mobile device. Make sure to log the events from each table callback
  3. Background the app (go to home or a different app)
  4. Make some changes to the DB tables
  5. When you re-enter the app, check the logs. The changes you made to the DB tables should be published not only to the callbacks for those tables, but also all of the other callbacks
 this.dataChannel = this.supabase
      .channel("schema-db-changes")
      .on(
        "postgres_changes",
        {
          schema: "public",
          table: "table1",
          event: "*",
        },
        (e) => console.log("Table 1: ", e)
      )
      .on(
        "postgres_changes",
        {
          schema: "public",
          table: "table2",
          event: "*",
        },
        (e) => console.log("Table 2: ", e)
      )
      .on(
        "postgres_changes",
        {
          schema: "public",
          table: "table3",
          event: "*",
        },
        (e) => console.log("Table 3: ", e)
      )

Expected behavior

I would expect the data for table1 to only go to the callback for table1

Screenshots

These are screenshots of logs from my own application.

Screenshot 2024-11-04 at 9 47 48 PM

System information

  • OS: macOS
  • Browser: Chrome
  • Version of supabase-js: 2.46.1
  • Version of Node.js: 22.10.0

Additional context

Add any other context about the problem here.

@Justinyu1618 Justinyu1618 added the bug Something isn't working label Nov 5, 2024
@jeremiahblanch
Copy link

I just had something similar. I had to put a guard up like this to actually check the table in the payload against the table I had subscribed to:

const channel = client
   .channel(tableName)
  .on(
    'postgres_changes',
    { event: 'UPDATE', schema: '*' },
    (payload) => {
      if (payload.table !== tableName) {
        // only handle if this is the table that we subscribed to
        return;
      }

      // handle the updates
    },
  )

I haven't had time to drill down into the exact scenario that causes it. It only happens in one place in my app.

I'm on desktop
Windows.
Supabase version 1.200.3

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

2 participants