Skip to content

fix(server): use ufo for query parsing to fix h3 v2 compatibility#493

Merged
atinux merged 7 commits into
mainfrom
fix/getkey-h3-v2-invalid-url
Jun 2, 2026
Merged

fix(server): use ufo for query parsing to fix h3 v2 compatibility#493
atinux merged 7 commits into
mainfrom
fix/getkey-h3-v2-invalid-url

Conversation

@benjamincanac

@benjamincanac benjamincanac commented May 27, 2026

Copy link
Copy Markdown
Member

Summary

  • Stop using h3's getQuery/getRequestURL in the icon API handler and getKey. Both throw ERR_INVALID_URL under h3 v2.
  • Parse event.path using ufo parsePath and parseQuery for h3 v1 and v2 compatibility

…ix h3 v2 compatibility

`getQuery(event)` in the `getKey` callback throws `ERR_INVALID_URL` under h3 v2
because it calls `new URL(event.req.url)` with a relative path. Use `getRequestURL`
which already handles this correctly and is used in the handler body.
@benjamincanac
benjamincanac requested review from antfu and pi0 May 27, 2026 13:34
@coderabbitai

coderabbitai Bot commented May 27, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The PR replaces h3 query helpers by parsing event.path with ufo's parsePath/parseQuery, normalizes the parsed icons query into a comma-split icons array in the cached icon handler, updates the fallback apiUrl to ./.json?icons=..., and changes SWR getKey to hash icons.join(','). package.json dependencies add ufo and remove pathe from the dependencies block.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and specifically summarizes the main change: switching to ufo for query parsing to fix h3 v2 compatibility, which is the central objective of the PR.
Description check ✅ Passed The pull request description clearly explains the rationale for changes: addressing h3 v2 compatibility issues with getQuery/getRequestURL by switching to ufo's parsePath/parseQuery functions.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/getkey-h3-v2-invalid-url

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 and usage tips.

@benjamincanac
benjamincanac requested a review from danielroe June 1, 2026 13:32
@pkg-pr-new

pkg-pr-new Bot commented Jun 2, 2026

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

commit: 804068c

`getRequestURL` throws `ERR_INVALID_URL` under h3 v2 because `event.req.url`
is a relative path with no base. Parse `event.path` (relative in both h3 v1
and v2) against a dummy base instead, so query params can be read safely.
@benjamincanac benjamincanac changed the title fix(server): replace getQuery with getRequestURL in getKey to fix h3 v2 compatibility fix(server): parse event.path with a base url to fix h3 v2 compatibility Jun 2, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/runtime/server/api.ts (1)

19-21: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Wire the parsed URL into the handler.

getRequestURL is never called, so CI already fails on the unused helper, and the fallback branch still reads url.pathname / url.search at Line 64 even though url is no longer defined. Please initialize the parsed URL once in the handler and reuse it there.

Proposed fix
 export default defineCachedEventHandler(async (event: H3Event) => {
+  const url = getRequestURL(event)
   const options = useAppConfig().icon as NuxtIconRuntimeOptions
   const collectionName = event.context.params?.collection?.replace(/\.json$/, '')
   const collection = collectionName
     ? await collections[collectionName]?.()
     : null
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/runtime/server/api.ts` around lines 19 - 21, The handler never
initializes the parsed URL and getRequestURL is unused, so call
getRequestURL(event) at the start of the request handler (assign to a const
named url) and replace any direct references to event.path/event.url or the
undefined url variable with this parsed URL (use url.pathname and url.search
when building the request target); ensure getRequestURL(event) is the single
source of truth for URL parsing and remove any duplicate parsing/fallbacks that
cause the unused-helper or undefined-url issues.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/runtime/server/api.ts`:
- Around line 39-40: The icons query parsing currently yields [''] for
missing/empty values causing getIcons() and getKey() to see a bogus empty icon;
update the parsing logic around the iconsQuery/icons variables to normalize
empty or missing values into an empty array by splitting then filtering out
blank segments (e.g., remove empty strings and whitespace-only entries) so icons
becomes [] when no real icons are supplied; apply the same normalization to the
other occurrence referenced (lines ~88-90) so both places produce consistent
cache keys and handler behavior for empty icon queries.

---

Outside diff comments:
In `@src/runtime/server/api.ts`:
- Around line 19-21: The handler never initializes the parsed URL and
getRequestURL is unused, so call getRequestURL(event) at the start of the
request handler (assign to a const named url) and replace any direct references
to event.path/event.url or the undefined url variable with this parsed URL (use
url.pathname and url.search when building the request target); ensure
getRequestURL(event) is the single source of truth for URL parsing and remove
any duplicate parsing/fallbacks that cause the unused-helper or undefined-url
issues.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bdf5a196-10d0-40b4-bd95-2d3c1fae80fa

📥 Commits

Reviewing files that changed from the base of the PR and between 3aaa277 and 4a9aed9.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (2)
  • package.json
  • src/runtime/server/api.ts
✅ Files skipped from review due to trivial changes (1)
  • package.json

Comment thread src/runtime/server/api.ts Outdated
@atinux atinux changed the title fix(server): parse event.path with a base url to fix h3 v2 compatibility fix(server): use ufo for query parsing to fix h3 v2 compatibility Jun 2, 2026
@atinux
atinux merged commit 931722e into main Jun 2, 2026
5 checks passed
@atinux
atinux deleted the fix/getkey-h3-v2-invalid-url branch June 2, 2026 12:57
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.

2 participants