feat: realtime UI updates via Pusher/Soketi + TanStack Query invalidation (Phase 1 & 2)#98
Merged
kingRayhan merged 7 commits intomainfrom Apr 2, 2026
Merged
Conversation
4 tasks
…tion (Phase 1 & 2) Agent-Logs-Url: https://github.com/techdiary-dev/techdiary.dev/sessions/b073d05d-7457-4406-b59a-cafb8dac4c4d Co-authored-by: shoaibsharif <29075110+shoaibsharif@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add realtime state management with Soketi and TanStack Query
feat: realtime UI updates via Pusher/Soketi + TanStack Query invalidation (Phase 1 & 2)
Apr 1, 2026
- Eliminated the unused 'lt' import from the article-cleanup-service.ts file, streamlining the code and improving clarity.
- Deleted the Pusher private-channel auth endpoint to streamline the codebase. - Updated the Pusher client configuration to use a new auth endpoint and simplified the initialization process, enhancing clarity and maintainability.
- Replaced Pusher client and server imports with a unified publishMessage function for better abstraction. - Updated environment variable validation to require non-empty values for Pusher-related keys. - Removed deprecated Pusher client and server files to streamline the codebase.
- Added a comma after the number 4 in the array splice method to ensure correct syntax and prevent potential errors in the ArticleFeed component.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds Pusher/Soketi-protocol realtime signalling so browsers invalidate TanStack Query caches on push events instead of polling. The database and server actions remain the source of truth; the socket carries only event names plus a small payload (e.g.
scope).Dependencies
pusher(server) andpusher-js(browser)Environment (
src/env.ts)Pusher-related variables are required when running the app:
PUSHER_WS_HOSTPUSHER_APP_ID,PUSHER_APP_KEY,PUSHER_APP_SECRETNEXT_PUBLIC_PUSHER_APP_KEYNEXT_PUBLIC_PUSHER_WS_HOSTModule layout (
src/lib/pusher/)realtime-events.tsREALTIME_PUSHER_EVENTS(const object),RealtimePusherEvent(union),RealtimeListenHandlers(typed handler map). Add new events here so listeners and triggers stay aligned.pusher.server.tspusherServer;publishMessage(channel, event, data?)whereeventisRealtimePusherEvent(best-effort; logs broker failures, must not break callers). Re-exportsREALTIME_PUSHER_EVENTS.pusher.client.tslistenChannel(channel, handlers)withhandlers: RealtimeListenHandlers(only known event keys; excess keys are a type error). Re-exports event types andREALTIME_PUSHER_EVENTS.Registered events (
REALTIME_PUSHER_EVENTS)NOTIFICATION_NEWnotification.newCOMMENT_CREATEDcomment.createdCOMMENT_UPDATEDcomment.updatedCOMMENT_DELETEDcomment.deletedCall sites use
[REALTIME_PUSHER_EVENTS.…](listeners) andREALTIME_PUSHER_EVENTS.…(publishMessage) to avoid string drift.Client API —
listenChannelObject-only API; each key must be a
RealtimePusherEvent:Returns an unsubscribe function for
useEffectcleanup.Private channel auth
POST /api/socket/auth(src/app/api/socket/auth/route.ts)private-user.{authenticatedUserId}(403 for any other private channel name).pusher-jsusesauthEndpoint: "/api/socket/auth"andwsHost/ key from public env.Phase 1 — Notifications
After the Inngest handler inserts a notification row, it calls
publishMessage(private-user.${recipientId}, REALTIME_PUSHER_EVENTS.NOTIFICATION_NEW, { scope: "notifications" }).RealtimeProvidersubscribes withlistenChannelon the signed-in user’s private channel and invalidatesmy-notificationsandunread-notification-count.Phase 2 — Comments
comment.action.tscallspublishMessageonresource.{RESOURCE_TYPE}.{resourceId}withCOMMENT_CREATED,COMMENT_UPDATED, orCOMMENT_DELETEDafter each mutation.CommentSectionuseslistenChannelon mount and invalidates the comments query on those events.Public
resource.*channels let anonymous readers on a public article receive live comment updates without private-channel auth.Channel naming
private-user.{userId}/api/socket/auth)resource.{TYPE}.{id}Updates since the initial merge description: modules under
src/lib/pusher/includingrealtime-events.ts, typed events shared bylistenChannelandpublishMessage, object-only listener API,PUSHER_WS_HOST/NEXT_PUBLIC_PUSHER_WS_HOST, and auth at/api/socket/auth.