Repository navigation
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Mark the default initializer as pure src/index.ts |
A pure annotation marks the default createFetch({ fetch }) call, allowing bundlers to remove it when unused. |
Priority:
Estimated code review effort: 1 (Trivial) | ~3 minutes
Change: Bug fix · Severity of issue fixed: Low
Possibly related PRs
- unjs/ofetch#641: It adds a pure annotation to the same
createFetch({ fetch })initialization.
Suggested reviewers: pi0
Merge Risk: 
Minimal · up to 166e7
-
No actionable merge-blocking risk remains.
Pre-merge checks: 
5
-
Full details: Title check
-
Explanation
The title names the main change: the default client creation in src/index.ts is now marked with a /*
@__PURE__*/ annotation so bundlers can drop it when unused. The title is specific, concise, and matches the raw summary, which describes the same annotation on the createFetch call and its tree-shaking purpose. The PR objectives (PR#644and issue#642) describe the same goal of removing the unused default fetch client when only FetchError is imported.
Full details: Linked Issues check
-
Explanation
Issue
#642requires that the unused default client is not retained when a bundle imports only FetchError. The reviewed head marks the default client creation in src/index.ts as pure:export const ofetch: $Fetch = /* @__PURE__ */ createFetch({ fetch });. This is the only coding change needed for the default-client retention. I checked the callee:createFetchin src/fetch.ts declares local functions and closures, assigns properties only to its own returned$fetchfunction object, and does not mutate globals. The call argument{ fetch }is a plain object literal. The annotation is therefore consistent with the code. The byte-size result (6,070 B to 364 B) is the author's reported measurement. I did not rebuild the reproduction, so that figure is unverified here. No automated test was added. The issue does not request one, so this does not fail the requirement. The issue's non-coding instruction to run the reproduction is not a coding requirement.
Full details: Out of Scope Changes check
-
Explanation
The whole-PR diff against the merge base changes only src/index.ts. It adds a two-line explanatory comment and the
/* @__PURE__ */annotation on theofetchdefault client. Both changes directly implement the#642objective. No unrelated files or behavior changes appear in the diff. The$fetchalias and thefetchwrapper are unchanged.
Full details: Docstring Coverage
-
Explanation
No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 1 files.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Comment @coderabbitai help to get the list of available commands.
Summary
When a consumer imports only an export that has no runtime dependency on the default client — e.g.
import { FetchError } from "ofetch"— the defaultcreateFetch({ fetch })instance is still evaluated and retained by bundlers, because the call is not marked side-effect free. This inflates the bundle for the common "only useFetchError" case.This marks the default client creation with
/* @__PURE__ */so bundlers (esbuild / rollup / webpack) can drop it via tree-shaking when the defaultofetch/$fetchexport is unused.Fixes #642.
Change
createFetchis a pure factory: it only readsglobalThis.fetchas a default and returns a closure, without mutating any global state. The package already declares"sideEffects": false, so the annotation is safe.Testing
pnpm build(obuild) succeeds.pnpm exec vitest run→ 28/28 tests pass.pnpm exec eslint src/index.ts→ clean.Per the issue's reproduction (https://github.com/onmax/repros/tree/repro/ofetch-pure-initializers), a minified bundle for an entry importing only
FetchErrordrops from ~6070 B to ~364 B.Summary by CodeRabbit