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

Merged
merged 3 commits into from
Jun 26, 2025

Conversation

zimiovid
Copy link
Contributor

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 26, 2025 9:30am

@zimiovid
Copy link
Contributor Author

Hey! Thanks for the pr!

Let's add

setGistId(shareId)

in loadFromGist() for now

Done.

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.

Can you fix the formatting as well? The semicolon, the spaces

@zimiovid
Copy link
Contributor Author

zimiovid commented Jun 26, 2025

Can you fix the formatting as well? The semicolon, the spaces

My bad. Got 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.

Looks great, thank you!

@1ilit 1ilit merged commit f1d6325 into drawdb-io:main Jun 26, 2025
3 checks passed
ewqazxc pushed a commit to ewqazxc/drawdb that referenced this pull request Jul 4, 2025
…on (drawdb-io#511)

* fix: prevent duplicate gist creation

* feat: change from useEffect to loadFromGist

* Update Workspace.jsx
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