Skip to content

feat: realtime manager #1982

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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

satya-nutella
Copy link
Contributor

@satya-nutella satya-nutella commented May 31, 2025

Description

Related Issues

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Release
  • Refactor
  • Other (please describe):

Testing

Screenshots (if applicable)

Additional Notes

This PR depends on #1980


Important

Introduce RealtimeManager for handling real-time user and frame events in the editor using Supabase.

  • RealtimeManager:
    • New RealtimeManager class in realtime/manager.ts to manage real-time events using Supabase.
    • Handles user and frame events: USER_UPDATED, FRAME_CREATED, FRAME_UPDATED, FRAME_DELETED.
    • Manages subscriptions and broadcasts events to a Supabase channel.
  • Integration:
    • EditorEngine in engine.ts now includes RealtimeManager.
    • CanvasManager and FramesManager send real-time events on user and frame updates.
  • Models:
    • New RealtimeEventType and event interfaces in realtime/index.ts.
    • RealtimeUser interface extends UserMetadata with position data.
  • Misc:
    • Add realtimeManager context in realtime/index.ts for React components.

This description was created by Ellipsis for 6f29cf6. You can customize this summary. It will automatically update as commits are pushed.

…ts and canvases

- Implemented helper functions `user_has_project_access` and `user_has_canvas_access` to check user roles.
- Created row-level security policies for `projects`, `canvas`, `user_projects`, `user_canvases`, `frames`, `users`, `user_settings`, and `project_invitations` to enforce access control based on user roles.
- Ensured only authenticated users can perform actions based on their roles in the respective tables.
- Added "db:migrate" command to package.json for both bun and drizzle-kit.
- Created a GitHub Actions workflow for deploying Supabase migrations, ensuring migrations run on workflow dispatch.
- Made existing SQL migrations idempotent by adding checks for type and table existence before creation.
- Updated various migration files to drop constraints and types if they exist, enhancing database integrity and flexibility.
- Changed the trigger logic to handle `conversations` and `messages` instead of `frames`, `user_canvases`, and `canvas`.
- Updated SQL to ensure project_id is correctly fetched based on the new table structure.
- Dropped obsolete triggers and created new ones for `conversations` and `messages` to maintain row-level security policies.
- Created layout component for invitation pages with metadata.
- Implemented main component to display invitation details and handle acceptance.
- Enhanced API to return inviter information and handle not found cases.
- Integrated useRouter for navigation after accepting an invitation.
- Updated acceptInvitationMutation to redirect users to the projects page upon successful acceptance.
- Improved code structure by importing necessary hooks from next/navigation.
- Updated the `sendInvitationEmail` function to await the rendering of the invitation email when `dryRun` is true, ensuring the rendered output is correctly logged before returning.
- Introduced `FeatureFlagsProvider` to manage feature flags based on environment variables.
- Added `NEXT_PUBLIC_FEATURE_COLLABORATION` flag to control the visibility of the `Members` component in the `TopBar`.
- Updated `env.ts` to include the new feature flag and modified `layout.tsx` to wrap the application in the `FeatureFlagsProvider`.
- Added `RealtimeManager` to handle real-time updates for users and frames.
- Updated `EditorEngine` and `CanvasManager` to utilize the new `realtime` functionality for broadcasting user updates and frame events.
- Enhanced `FramesManager` to send events for frame creation, update, and deletion.
- Introduced new types and events in the `realtime` module for better type safety and clarity.
- Updated context providers to include `realtimeManager` for managing real-time interactions.
Copy link

vercel bot commented May 31, 2025

@satya-nutella is attempting to deploy a commit to the Onlook Team on Vercel.

A member of the Team first needs to authorize it.

@Kitenite Kitenite marked this pull request as ready for review May 31, 2025 20:41
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

Looks good to me! 👍

Reviewed everything up to 6f29cf6 in 1 minute and 38 seconds. Click for details.
  • Reviewed 349 lines of code in 9 files
  • Skipped 0 files when reviewing.
  • Skipped posting 5 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. apps/web/client/src/components/store/editor/canvas/index.ts:29
  • Draft comment:
    Duplicate USER_UPDATED broadcast logic appears in two places. Consider extracting a helper to avoid repetition.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
2. apps/web/client/src/components/store/editor/frames/index.ts:250
  • Draft comment:
    FRAME_UPDATED events are sent in two different update paths. Confirm if duplicate broadcasting is intentional or if they should be consolidated.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None
3. apps/web/client/src/components/store/editor/realtime/manager.ts:66
  • Draft comment:
    In the send() method, the entire event is sent as payload. Consider sending only event.payload to avoid nested redundancy.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable: usefulness confidence = 20% vs. threshold = 50% Without seeing the RealtimeEvent type definition, we can't be sure if event.payload exists or if sending the full event object is actually the intended behavior. The comment makes an assumption about the data structure that we can't verify. The change could potentially break functionality if the receiving end expects the full event object. I might be too cautious - if the type is called RealtimeEvent, it's reasonable to assume it follows a standard event pattern with a payload property. Even if it's a reasonable assumption, we shouldn't make changes to data structures without being completely certain of the type definitions and the requirements of the receiving end. Delete the comment since we don't have enough context to verify if the suggested change is correct or necessary.
4. apps/web/client/src/components/store/editor/realtime/manager.ts:10
  • Draft comment:
    RealtimeManager.init() relies on projectManager.project.id and logs an error if not set. Consider handling dynamic project changes to reinitialize the subscription when a project becomes available.
  • Reason this comment was not posted:
    Confidence changes required: 50% <= threshold 50% None
5. PR Description:1
  • Draft comment:
    The PR title indicates a 'realtime manager' feature, but the description references onboarding docs updates. Please align the PR description with the actual code changes.
  • Reason this comment was not posted:
    Comment was not on a location in the diff, so it can't be submitted as a review comment.

Workflow ID: wflow_4oURyg3n4jIewWow

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

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

Successfully merging this pull request may close these issues.

2 participants