Skip to content

Share identical requests, abort unused ones, ship a source map - #48

Open
cwooley wants to merge 1 commit into
masterfrom
charles/fetch-dedupe-sourcemap
Open

cwooley wants to merge 1 commit into
masterfrom
charles/fetch-dedupe-sourcemap

Conversation

@cwooley

@cwooley cwooley commented Nov 25, 2026

Copy link
Copy Markdown
Member

Addresses #46 (ARAD-OGR-005) and #47 (ARAD-OGR-011), the two retest follow-ups for this package.

#46: requests made from each visitor's browser

The README warning and proxyUrl mode were already done. What the retest left open: the component fetched on every mount, with no abort, no sharing and no reuse. In direct mode each of those requests spends the site's API key.

  • Sharing: new src/util/requestResults.js. Cards asking for the same URL share one request, and a successful answer is reused for 60 seconds. Error responses and failed requests are not remembered. forceCacheUpdate always makes a new request.
  • Abort: when the last card waiting for a request unmounts, the request is aborted. The abort is decided one tick later, so React StrictMode's unmount-and-remount reuses the request instead of starting a second one.
  • No state updates after unmount.
  • README gains a short "How many requests a card makes" section.

Not changed: direct mode still sends app_id in the URL. That is the documented design, and removing it would break every existing user; proxyUrl is the way to keep the key off the page.

#47: the published bundle

CI, prepublishOnly, the files allowlist and npm publish --provenance already exist. Two things were open:

  • No source map. webpack.config.js now sets devtool: 'source-map'; build/index.js.map ships (checked with npm pack --dry-run).
  • 2.5.0 has no provenance. It was published by hand on 2026-10-07 from a commit that was never pushed, so its gitHead is not on GitHub and npm shows no attestation. This PR sets the version to 2.5.1.

After merge (needs a person)

  1. Tag the merge commit v2.5.1 and push the tag. CI publishes it with provenance.
  2. Check: npm view opengraph-react@2.5.1 dist.attestations is not empty.
  3. Decide whether to run npm deprecate opengraph-react@2.5.0 "Published without provenance; use 2.5.1".

Behaviour change to know about

A card mounted within 60 seconds of an identical one shows the earlier answer instead of fetching again. Pass forceCacheUpdate where a fresh fetch on every mount is wanted.

Testing

  • npm test: 32 passing (8 new). With the old src/index.js restored, 6 of the new tests fail.
  • New cases: three identical cards make one request; StrictMode makes one request and does not abort it; a later mount reuses the answer and a different site does not; forceCacheUpdate refetches; the request is aborted when its only card unmounts and kept while another card waits; errors are not remembered; no update after unmount.
  • npm run build succeeds and emits index.js and index.js.map.

🤖 Generated with Claude Code

)

#46 (ARAD-OGR-005 follow-up): every mount issued its own fetch with no
abort, so one link shown several times, a re-mounted list or React
StrictMode multiplied the requests made against the API key from each
visitor's browser.

- requestResults shares one request between cards asking for the same
  URL and reuses a successful answer for 60 seconds. Error responses
  and failed requests are not remembered. forceCacheUpdate always asks
  again.
- A request is aborted once no mounted card is waiting for it, and a
  card no longer updates state after it unmounts.

#47 (ARAD-OGR-011 follow-up): the published bundle had no source map.

- webpack emits build/index.js.map, which the files allowlist already
  ships.
- Version 2.5.1, to be published by CI from a v2.5.1 tag so the release
  carries provenance (2.5.0 was published by hand).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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