Skip to content

fix(server): dedupe remote collection requests - #535

Open
onmax wants to merge 1 commit into
nuxt:mainfrom
onmax:fix/dedupe-remote-collection-requests
Open

fix(server): dedupe remote collection requests#535
onmax wants to merge 1 commit into
nuxt:mainfrom
onmax:fix/dedupe-remote-collection-requests

Conversation

@onmax

@onmax onmax commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🔗 Linked issue

Resolves #534.

📚 Description

Concurrent server API requests for different icons in one cold remote collection each started a full collection download. createRemoteCollection assigned its cache after fetch(...).json() resolved, so overlapping callers all saw an empty cache.

This stores the pending operation immediately, then replaces it with the resolved collection. A fetch or JSON parse rejection clears the cache so a later request can retry. Falsey JSON values retain the existing retry behavior.

cold caller A ─┐
cold caller B ─┼─> one pending collection fetch ─> resolved cache
cold caller C ─┘

fetch/JSON error ─> clear pending cache ─> later caller retries

The production Node repro holds origin responses until requests overlap. With 20 consumers of one 49,940-byte collection:

Before After
Cold origin requests 20 1
Cold origin body bytes 998,800 49,940
Extra requests for 20 warm icon keys 0 0

Copy/paste repro (published package, then pnpm patch):

git clone --depth 1 --branch repro/nuxt-icon-perf-remote-collection-dedup https://github.com/onmax/repros.git nuxt-icon-repro
cd nuxt-icon-repro/nuxt-icon-perf-remote-collection-dedup
npx --yes --package=node@24.19.0 --package=pnpm@11.15.1 --call 'pnpm install --frozen-lockfile && pnpm verify'
cd ../nuxt-icon-perf-remote-collection-dedup-fix
npx --yes --package=node@24.19.0 --package=pnpm@11.15.1 --call 'pnpm install --frozen-lockfile && pnpm verify'

The verifier also checks recovery after invalid JSON and after a null collection result. It uses distinct icon API keys so Nitro's response cache does not hide collection-level requests.

Validation:

pnpm run test:unit --run --maxWorkers=1
# 7 files, 32 tests passed

pnpm exec eslint src/bundle-server.ts test/server-bundle.test.ts
pnpm typecheck
pnpm build

The cache is process-local and applies to remote server bundles.

@pkg-pr-new

pkg-pr-new Bot commented Sep 4, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/@nuxt/icon@535

commit: fc64460

@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 9d79f78f-b7eb-4f9f-b4ca-2ceebe5bd7a0

📥 Commits

Reviewing files that changed from the base of the PR and between b878f5b and fc64460.

📒 Files selected for processing (2)
  • src/bundle-server.ts
  • test/server-bundle.test.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The server bundle now caches the in-flight promise for each remote collection. Concurrent calls share one fetch. Rejected fetches and JSON parsing failures clear the cache and allow retries. Falsy collection results are not retained. New tests load the generated server bundle and verify concurrent deduplication, successful caching, failure retries, and retries after falsy responses.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to fc644

Remote icon collections now share concurrent downloads while retaining caching and retry behavior after failed or falsy responses. The covered behavior is ready to merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: deduplicating remote collection requests in the server bundle.
Description check ✅ Passed The description is directly related to the changes. It explains the concurrency issue, cache behavior, retry behavior, performance impact, and validation results.
Linked Issues check ✅ Passed The implementation satisfies issue #534 by caching the pending fetch, sharing it across concurrent callers, preserving resolved caching, and clearing the cache after fetch, JSON, or falsey-result fail…
Out of Scope Changes check ✅ Passed The changes are limited to the remote collection cache fix and targeted tests for concurrency, caching, and retry behavior. No unrelated code changes are identified.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/bundle-server.ts

Parsing error: Unexpected token {

test/server-bundle.test.ts

Parsing error: Unexpected token {


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

Remote server bundle duplicates concurrent collection downloads

1 participant