npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@m1212e/urql-crosstab-sync

v0.1.0

Published

A urql exchange that mirrors mutations and query results between same-origin browser tabs over BroadcastChannel, keeping graphcache state (including optimistic updates) in sync.

Readme

@m1212e/urql-crosstab-sync

A urql exchange that mirrors mutations and query results between same-origin browser tabs over BroadcastChannel, so cache state stays in sync — including optimistic updates from @urql/exchange-graphcache.

When a user fires a mutation in tab A, every other tab plays the same mutation through its own graphcache: optimistic update on dispatch, real data on success, rollback on error. No extra wiring inside your graphcache config — it just sees a mutation come through the pipeline.

Install

bun add @m1212e/urql-crosstab-sync
# or
npm i @m1212e/urql-crosstab-sync

Peer deps: @urql/core ^6, wonka ^6.

Setup

The exchange must sit between cacheExchange (graphcache) and fetchExchange:

import { createClient, fetchExchange } from "@urql/core";
import { cacheExchange } from "@urql/exchange-graphcache";
import { crossTabSyncExchange } from "@m1212e/urql-crosstab-sync";

const client = createClient({
  url: "/graphql",
  exchanges: [
    cacheExchange({
      /* your graphcache config: optimistic, updates, resolvers, ... */
    }),
    crossTabSyncExchange(),
    fetchExchange,
  ],
});

That placement matters: the sync exchange relies on graphcache having already applied its optimistic phase on outbound mutations, and it needs to be able to short-circuit the network for synthetic operations triggered by other tabs.

What gets synced

| Event in tab A | What tab B does | | ------------------------------- | -------------------------------------------------------------- | | Mutation starts | Dispatches the same mutation — graphcache runs optimistic | | Mutation succeeds | Resolves tab B's synthetic mutation with the real result | | Mutation errors | Resolves tab B's mutation with the same error → graphcache rolls back | | Query result returns from network | Writes the same data into tab B's cache (synthetic query) |

Subscriptions and teardowns are forwarded normally and never broadcast.

Options

crossTabSyncExchange({
  channelName: "urql-crosstab-sync", // BroadcastChannel name
  tabId: undefined,                  // defaults to crypto.randomUUID()
  shouldSync: (op) => true,          // predicate to opt operations out of sync
  syncMutations: true,
  syncQueries: true,
  debug: false,                      // `true` → console.debug, or pass `(event, data) => ...`
});

shouldSync is the escape hatch you want for things like login/logout mutations:

crossTabSyncExchange({
  shouldSync: (op) => {
    const name = op.query.definitions[0];
    if (name?.kind === "OperationDefinition" && name.name?.value === "Login") {
      return false;
    }
    return true;
  },
});

Outside the browser (SSR, Node), the exchange becomes a passthrough — safe to include in isomorphic client setups.

Caveats

  • Variables and result data must be structured-cloneable (BroadcastChannel.postMessage uses the structured clone algorithm). Date, Map, Set, typed arrays, File, and Blob work; closures, class instances with private fields, and DOM nodes don't. A failed postMessage is caught and logged via console.warn; it won't break the originating tab's mutation.
  • The protocol assumes all tabs are running the same schema and the same graphcache config. If two tabs disagree on optimistic or updates handlers, their caches will drift.
  • If two tabs fire the same mutation concurrently, each tab will execute its own original mutation and a synthetic replay of the other tab's — the final cache state is correct but you'll see two server round-trips. Use shouldSync to opt out for mutations where that's undesirable.
  • If tab A closes before its mutation result arrives, tab B's optimistic update will not be rolled back automatically. This may be addressed in a later version with a pending-mutation timeout.

License

Apache-2.0