Skip to content

Fix shortlink mutations not reflecting in UI due to fire-and-forget revalidation#9

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/improve-implementation-callbacks
Draft

Fix shortlink mutations not reflecting in UI due to fire-and-forget revalidation#9
Copilot wants to merge 2 commits into
mainfrom
copilot/improve-implementation-callbacks

Conversation

Copilot AI commented Mar 14, 2026

Copy link
Copy Markdown

After creating, editing, or deleting a shortlink, the UI would intermittently not update because revalidate() was called without being awaited — the fetch ran in the background while the component finished rendering with stale data.

Changes

  • useFetch.tsrevalidate now returns Promise<void> instead of void so callers can properly await it
  • ShortlinksContainer.tsxcreateShortlink awaits revalidate(), only revalidates on confirmed success, and shows toast feedback for both success and failure cases
  • Editor/index.tsxsaveData awaits revalidate() and auto-closes the modal after a successful save
  • Menu/Link/index.tsxdeleteLink awaits revalidate()
  • Button/index.tsxclickHandler uses try/finally so isLoading always resets even when the callback throws

Before / After

// Before — fire-and-forget, UI races ahead of the fetch
const createShortlink = async () => {
  await instance.post(`/api/db`, { ... });
  revalidate(); // not awaited
};

// After — button stays in loading state until list is refreshed
const createShortlink = async () => {
  const { data } = await instance.post(`/api/db`, { ... });
  if (data.success) {
    toast.success("Shortlink created successfully!");
    await revalidate(); // blocks until fresh data is in state
  } else {
    toast.error("Failed to create shortlink. Please try again.");
  }
};

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • download.cypress.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node index.js --exec install (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

@codesandbox

codesandbox Bot commented Mar 14, 2026

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@vercel

vercel Bot commented Mar 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pepper Ready Ready Preview, Comment Mar 14, 2026 7:06pm
sarfraz-alam-links Error Error Mar 14, 2026 7:06pm

Co-authored-by: Sarfraz-droid <73013838+Sarfraz-droid@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve implementation of callbacks for shortlink generation Fix shortlink mutations not reflecting in UI due to fire-and-forget revalidation Mar 14, 2026
Copilot AI requested a review from Sarfraz-droid March 14, 2026 19:06
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