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

webSocket connection to 'wss//.....' failed: #2

Open
ashiyang opened this issue Feb 18, 2022 · 0 comments
Open

webSocket connection to 'wss//.....' failed: #2

ashiyang opened this issue Feb 18, 2022 · 0 comments

Comments

@ashiyang
Copy link

First, thank you very much for sharing how to make todolist app in Next.js & supaBase, it help me a lot.

I'm not familiar with React and supaBase, here I have some issue when I followed your tutorial in freeCodeCamp,

I always get error in Chrome console like this
webSocket connection to 'wss//.....' failed:

and i think the error is from these code in index.js

useEffect(() => {
    const todoListener = supabaseClient
      .from("todos")
      .on("*", (payload) => {
        if (payload.eventType !== "DELETE") {
          const newTodo = payload.new;
          setTodos((oldTodos) => {
            const exists = oldTodos.find((todo) => todo.id === newTodo.id);
            let newTodos;
            if (exists) {
              const oldTodoIndex = oldTodos.findIndex(
                (obj) => obj.id === newTodo.id
              );
              oldTodos[oldTodoIndex] = newTodo;
              newTodos = oldTodos;
            } else {
              newTodos = [...oldTodos, newTodo];
            }
            newTodos.sort((a, b) => b.id - a.id);
            return newTodos;
          });
        }
      })
      .subscribe();

    return () => {
      todoListener.unsubscribe();
    };
  }, []);

but i have no idea to fix it....

because when I update todo or add new todo, it cannot show the new state for todos, i need refresh again to fetch new todos.

thank you.

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

No branches or pull requests

1 participant