Skip to content

fix: try not to make network requests with prefer offline - #10334

Merged
zkochan merged 3 commits into
pnpm:mainfrom
samchungy:try-not-tomake-network-requests
Dec 21, 2025
Merged

fix: try not to make network requests with prefer offline#10334
zkochan merged 3 commits into
pnpm:mainfrom
samchungy:try-not-tomake-network-requests

Conversation

@samchungy

@samchungy samchungy commented Dec 19, 2025

Copy link
Copy Markdown
Contributor

I noticed when using --prefer-offline pnpm would still attempt to make network calls despite already having the package within the cache.

This stops pnpm from making some network calls when the package already exists within the cache when using --prefer-offline.

@samchungy
samchungy requested a review from zkochan as a code owner December 19, 2025 07:30
Copilot AI review requested due to automatic review settings December 19, 2025 07:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes the behavior of the preferOffline mode to prevent unnecessary network requests when cached metadata exists. Previously, preferOffline would still attempt network requests even when valid cached data was available.

Key Changes:

  • Modified the condition to return early when cached metadata is found in preferOffline mode
  • Moved the error throwing logic to only apply in offline mode, not preferOffline mode
  • Added comprehensive test coverage to verify no network requests occur with preferOffline when cache exists

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
resolving/npm-resolver/src/pickPackage.ts Updated logic to return cached metadata immediately in preferOffline mode and only throw errors in strict offline mode
resolving/npm-resolver/test/index.ts Added test case verifying that preferOffline uses cached metadata without making network requests

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@samchungy
samchungy force-pushed the try-not-tomake-network-requests branch from 54d297b to 1b75e00 Compare December 19, 2025 07:32
Comment thread .changeset/open-laws-pull.md Outdated
@zkochan
zkochan merged commit 1bc6b5a into pnpm:main Dec 21, 2025
10 checks passed
dadezzz pushed a commit to dadezzz/university_notes that referenced this pull request Dec 29, 2025
This PR contains the following updates:

| Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [pnpm](https://pnpm.io) ([source](https://github.com/pnpm/pnpm/tree/HEAD/pnpm)) | [`10.26.1` → `10.26.2`](https://renovatebot.com/diffs/npm/pnpm/10.26.1/10.26.2) | ![age](https://developer.mend.io/api/mc/badges/age/npm/pnpm/10.26.2?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/pnpm/10.26.1/10.26.2?slim=true) |

---

### Release Notes

<details>
<summary>pnpm/pnpm (pnpm)</summary>

### [`v10.26.2`](https://github.com/pnpm/pnpm/releases/tag/v10.26.2): pnpm 10.26.2

[Compare Source](pnpm/pnpm@v10.26.1...v10.26.2)

#### Patch Changes

- Improve error message when a package version exists but does not meet the `minimumReleaseAge` constraint. The error now clearly states that the version exists and shows a human-readable time since release (e.g., "released 6 hours ago") [#&#8203;10307](pnpm/pnpm#10307).

- Fix installation of Git dependencies using annotated tags [#&#8203;10335](pnpm/pnpm#10335).

  Previously, pnpm would store the annotated tag object's SHA in the lockfile instead of the actual commit SHA. This caused `ERR_PNPM_GIT_CHECKOUT_FAILED` errors because the checked-out commit hash didn't match the stored tag object hash.

- Binaries of runtime engines (Node.js, Deno, Bun) are written to `node_modules/.bin` before lifecycle scripts (install, postinstall, prepare) are executed [#&#8203;10244](pnpm/pnpm#10244).

- Try to avoid making network calls with preferOffline [#&#8203;10334](pnpm/pnpm#10334).

#### Platinum Sponsors

<table>
  <tbody>
    <tr>
      <td align="center" valign="middle">
        <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fpnpm%2Fpnpm%2Fpull%2F%3Ca+href%3D"https://bit.dev/?utm_source=pnpm&utm_medium=release_notes" rel="nofollow">https://bit.dev/?utm_source=pnpm&utm_medium=release_notes" target="_blank"><img src="proxy.php?url=https%3A%2F%2Fgithub.com%2Fpnpm%2Fpnpm%2Fpull%2F%3Ca+href%3D"https://pnpm.io/img/users/bit.svg" rel="nofollow">https://pnpm.io/img/users/bit.svg" width="80" alt="Bit"></a>
      </td>
    </tr>
  </tbody>
</table>

#### Gold Sponsors

<table>
  <tbody>
    <tr>
      <td align="center" valign="middle">
        <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fpnpm%2Fpnpm%2Fpull%2F%3Ca+href%3D"https://discord.com/?utm_source=pnpm&utm_medium=release_notes" rel="nofollow">https://discord.com/?utm_source=pnpm&utm_medium=release_notes" target="_blank">
          <picture>
            <source media="(prefers-color-scheme: light)" srcset="https://pnpm.io/img/users/discord.svg" />
            <source media="(prefers-color-scheme: dark)" srcset="https://pnpm.io/img/users/discord_light.svg" />
            <img src="proxy.php?url=https%3A%2F%2Fgithub.com%2Fpnpm%2Fpnpm%2Fpull%2F%3Ca+href%3D"https://pnpm.io/img/users/discord.svg" rel="nofollow">https://pnpm.io/img/users/discord.svg" width="220" alt="Discord" />
          </picture>
        </a>
      </td>
      <td align="center" valign="middle">
        <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fpnpm%2Fpnpm%2Fpull%2F%3Ca+href%3D"https://coderabbit.ai/?utm_source=pnpm&utm_medium=release_notes" rel="nofollow">https://coderabbit.ai/?utm_source=pnpm&utm_medium=release_notes" target="_blank">
          <picture>
            <source media="(prefers-color-scheme: light)" srcset="https://pnpm.io/img/users/coderabbit.svg" />
            <source media="(prefers-color-scheme: dark)" srcset="https://pnpm.io/img/users/coderabbit_light.svg" />
            <img src="proxy.php?url=https%3A%2F%2Fgithub.com%2Fpnpm%2Fpnpm%2Fpull%2F%3Ca+href%3D"https://pnpm.io/img/users/coderabbit.svg" rel="nofollow">https://pnpm.io/img/users/coderabbit.svg" width="220" alt="CodeRabbit" />
          </picture>
        </a>
      </td>
      <td align="center" valign="middle">
        <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fpnpm%2Fpnpm%2Fpull%2F%3Ca+href%3D"https://workleap.com/?utm_source=pnpm&utm_medium=release_notes" rel="nofollow">https://workleap.com/?utm_source=pnpm&utm_medium=release_notes" target="_blank">
          <picture>
            <source media="(prefers-color-scheme: light)" srcset="https://pnpm.io/img/users/workleap.svg" />
            <source media="(prefers-color-scheme: dark)" srcset="https://pnpm.io/img/users/workleap_light.svg" />
            <img src="proxy.php?url=https%3A%2F%2Fgithub.com%2Fpnpm%2Fpnpm%2Fpull%2F%3Ca+href%3D"https://pnpm.io/img/users/workleap.svg" rel="nofollow">https://pnpm.io/img/users/workleap.svg" width="190" alt="Workleap" />
          </picture>
        </a>
      </td>
    </tr>
    <tr>
      <td align="center" valign="middle">
        <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fpnpm%2Fpnpm%2Fpull%2F%3Ca+href%3D"https://stackblitz.com/?utm_source=pnpm&utm_medium=release_notes" rel="nofollow">https://stackblitz.com/?utm_source=pnpm&utm_medium=release_notes" target="_blank">
          <picture>
            <source media="(prefers-color-scheme: light)" srcset="https://pnpm.io/img/users/stackblitz.svg" />
            <source media="(prefers-color-scheme: dark)" srcset="https://pnpm.io/img/users/stackblitz_light.svg" />
            <img src="proxy.php?url=https%3A%2F%2Fgithub.com%2Fpnpm%2Fpnpm%2Fpull%2F%3Ca+href%3D"https://pnpm.io/img/users/stackblitz.svg" rel="nofollow">https://pnpm.io/img/users/stackblitz.svg" width="190" alt="Stackblitz" />
          </picture>
        </a>
      </td>
      <td align="center" valign="middle">
        <a href="proxy.php?url=https%3A%2F%2Fgithub.com%2Fpnpm%2Fpnpm%2Fpull%2F%3Ca+href%3D"https://vite.dev/?utm_source=pnpm&utm_medium=release_notes" rel="nofollow">https://vite.dev/?utm_source=pnpm&utm_medium=release_notes" target="_blank">
          <img src="proxy.php?url=https%3A%2F%2Fgithub.com%2Fpnpm%2Fpnpm%2Fpull%2F%3Ca+href%3D"https://pnpm.io/img/users/vitejs.svg" rel="nofollow">https://pnpm.io/img/users/vitejs.svg" width="42" alt="Vite">
        </a>
      </td>
    </tr>
  </tbody>
</table>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi42NC4xIiwidXBkYXRlZEluVmVyIjoiNDIuNjQuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Co-authored-by: Renovate Bot <renovate@zarantonello.dev>
Co-committed-by: Renovate Bot <renovate@zarantonello.dev>
samchungy added a commit to samchungy/pnpm that referenced this pull request Jan 8, 2026
zkochan added a commit that referenced this pull request Jan 12, 2026
…10423)

* Revert "fix: try not to make network requests with prefer offline (#10334)"

This reverts commit 1bc6b5a.

* Add changeset

---------

Co-authored-by: Zoltan Kochan <z@kochan.io>
zkochan added a commit that referenced this pull request Jan 12, 2026
…10423)

* Revert "fix: try not to make network requests with prefer offline (#10334)"

This reverts commit 1bc6b5a.

* Add changeset

---------

Co-authored-by: Zoltan Kochan <z@kochan.io>
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.

3 participants