Skip to content

chore: fix flickering version changed modal#278

Open
Horusiath wants to merge 1 commit intomainfrom
fix/version-changed-flickering
Open

chore: fix flickering version changed modal#278
Horusiath wants to merge 1 commit intomainfrom
fix/version-changed-flickering

Conversation

@Horusiath
Copy link
Contributor

@Horusiath Horusiath commented Mar 6, 2026

Summary by Sourcery

Improve version change detection in collaborative sync to avoid reacting to invalid or irrelevant messages.

Bug Fixes:

  • Treat only valid, well-formed collab version identifiers as version changes to prevent spurious UI updates.
  • Ignore collab messages without update or syncRequest payloads when checking for version changes to avoid unnecessary version change handling.

@sourcery-ai
Copy link

sourcery-ai bot commented Mar 6, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refines how collaboration version IDs are validated and tightens the conditions under which a version change is detected to prevent spurious "version changed" behavior, likely addressing a flickering modal issue.

Sequence diagram for versionChanged detection logic

sequenceDiagram
  participant Caller
  participant SyncContext
  participant CollabMessage
  participant versionChanged
  participant isCollabVersionId

  Caller->>versionChanged: versionChanged(SyncContext, CollabMessage)
  activate versionChanged
  versionChanged->>CollabMessage: check update
  versionChanged->>CollabMessage: check syncRequest
  alt no update and no syncRequest
    versionChanged-->>Caller: false
  else has update or syncRequest
    versionChanged->>CollabMessage: read version (update.version or syncRequest.version)
    versionChanged->>SyncContext: read doc.version
    versionChanged->>isCollabVersionId: isCollabVersionId(incomingVersion)
    activate isCollabVersionId
    isCollabVersionId->>isCollabVersionId: UUID_REGEX.test(value)
    isCollabVersionId-->>versionChanged: incomingKnown
    deactivate isCollabVersionId
    versionChanged->>isCollabVersionId: isCollabVersionId(localVersion)
    activate isCollabVersionId
    isCollabVersionId->>isCollabVersionId: UUID_REGEX.test(value)
    isCollabVersionId-->>versionChanged: localKnown
    deactivate isCollabVersionId
    versionChanged->>versionChanged: compare versions based on known flags
    versionChanged-->>Caller: boolean
    deactivate versionChanged
  end
Loading

File-Level Changes

Change Details Files
Replace UUID library-based validation with an inline regex and narrow version-change detection to specific message types.
  • Introduce an in-module UUID_REGEX that validates v1–v8 UUIDs plus all-zero and all-ones sentinel values
  • Update isCollabVersionId to use the new UUID_REGEX instead of the external uuidValidate helper
  • Guard versionChanged to early-return false when the collab message is neither an update nor a syncRequest, limiting version change checks to those two types
src/components/ws/sync/types.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@Horusiath Horusiath requested a review from appflowy March 6, 2026 13:58
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The custom UUID_REGEX is fairly complex and encodes some special cases (all zeros/all fs); consider centralizing this as a shared UUID utility or adding inline comments breaking down the pattern to make future maintenance and updates easier.
  • The early return in versionChanged for messages without update or syncRequest changes its behavior scope; consider explicitly narrowing the collab.ICollabMessage type (e.g., via a union or type guard) so that the function’s intended input domain is enforced at the type level rather than via a runtime check.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The custom UUID_REGEX is fairly complex and encodes some special cases (all zeros/all fs); consider centralizing this as a shared UUID utility or adding inline comments breaking down the pattern to make future maintenance and updates easier.
- The early return in versionChanged for messages without update or syncRequest changes its behavior scope; consider explicitly narrowing the collab.ICollabMessage type (e.g., via a union or type guard) so that the function’s intended input domain is enforced at the type level rather than via a runtime check.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

};

export const isCollabVersionId = (value: string | null | undefined): value is string => {
return typeof value === 'string' && uuidValidate(value);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

You really don't need an entire dependency for a single regex test.

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.

1 participant