Skip to content

Fix: Always use gistId from URL for sharing, prevent duplicate gist creation #511

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 1 commit into
base: main
Choose a base branch
from

Conversation

zimiovid
Copy link

Problem:
Currently, when opening a diagram via a share link (?shareId=...), the gistId is not always set correctly in the app state. As a result, when the user tries to share again, a new gist is created instead of updating the existing one. This leads to unnecessary gist duplication and breaks the expected collaborative workflow.

Solution:

  • On Workspace mount, always set gistId from the shareId URL parameter if present.
  • Ensure that all share/patch operations use this gistId.
  • Now, if a user opens a diagram via a share link, further sharing will update the same gist, not create a new one.

Code changes:

  • In Workspace.jsx, add a useEffect to set gistId from the URL on mount:
    useEffect(() => {
      const params = new URLSearchParams(window.location.search);
      const shareId = params.get("shareId");
      if (shareId) {
        setGistId(shareId);
      }
    }, []);
  • In Share.jsx, use the current gistId for patching, and only create a new gist if gistId is empty:
    if (!gistId || gistId === "") {
      const id = await create(diagramToString());
      setGistId(id);
    } else {
      await patch(gistId, diagramToString());
    }

Result:

  • Sharing a diagram after opening it via a share link will now update the existing gist, not create a new one.
  • This makes sharing and collaboration more predictable and reliable.

Copy link

vercel bot commented Jun 24, 2025

@zimiovid is attempting to deploy a commit to the dottle's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Member

@1ilit 1ilit left a comment

Choose a reason for hiding this comment

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

Hey! Thanks for the pr!

Let's add

setGistId(shareId)

in loadFromGist() for now

Copy link

vercel bot commented Jun 25, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
drawdb ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 25, 2025 11:27am

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