Skip to content

fix: clientAddress undefined in production server functions (nitro-v2)#2122

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-client-address-undefined
Draft

fix: clientAddress undefined in production server functions (nitro-v2)#2122
Copilot wants to merge 2 commits intomainfrom
copilot/fix-client-address-undefined

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 28, 2026

getRequestEvent().clientAddress returns undefined in production when using @solidjs/vite-plugin-nitro-2, despite working in dev.

Root Cause

The virtual entry bridging Nitro (h3 v1) → solid-start (h3 v2) was:

import { fromWebHandler } from 'h3'
import handler from '${ssrEntryFile}'
export default fromWebHandler(handler.fetch)

Three things combine to drop the IP:

  1. h3 v1's fromWebHandler calls handler(toWebRequest(event), event.context)toWebRequest produces a plain Request with no IP metadata
  2. h3 v2's H3Core.fetch(request) ignores the second argument, so the context is never passed through
  3. h3 v2's getRequestIP checks event.req.context?.clientAddress and event.req.ip — both undefined on the converted request

Fix

Replace the fromWebHandler shorthand with an explicit eventHandler that extracts the IP from the outer Nitro h3 v1 event and attaches it to request.context before calling handler.fetch:

import { eventHandler, getRequestIP, toWebRequest } from 'h3'
import handler from '${ssrEntryFile}'
export default eventHandler((h3Event) => {
  const ip = getRequestIP(h3Event) ?? getRequestIP(h3Event, { xForwardedFor: true })
  const request = toWebRequest(h3Event)
  if (ip) {
    request.context = Object.assign(request.context || {}, { clientAddress: ip })
  }
  return handler.fetch(request)
})

h3 v2's H3Event constructor reads req.context as the event context, so getRequestIP subsequently finds event.req.context.clientAddress. The socket-based IP is tried first; xForwardedFor is used as fallback for reverse-proxy deployments.


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 28, 2026

⚠️ No Changeset found

Latest commit: e25e21a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 28, 2026

Deploy Preview for solid-start-landing-page ready!

Name Link
🔨 Latest commit e25e21a
🔍 Latest deploy log https://app.netlify.com/projects/solid-start-landing-page/deploys/69c80c8d963a4b000877d602
😎 Deploy Preview https://deploy-preview-2122--solid-start-landing-page.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI changed the title [WIP] Fix undefined client address in server functions fix: clientAddress undefined in production server functions (nitro-v2) Mar 28, 2026
Copilot AI requested a review from brenelz March 28, 2026 17:15
@brenelz
Copy link
Copy Markdown
Contributor

brenelz commented Mar 28, 2026

I think we are probably deprecating "nitro-v2" plugin soon so this might not be needed

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.

[Bug?]: getRequestEvent().clientAddress in server functions is undefined in prod

2 participants