-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
chore: upgrade h3 and cookie-es #7044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
62cf03d
0713e9b
97b4906
4d84574
c15834b
75c727f
dcff88a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,7 +19,7 @@ import { | |||||||||||||||||
| unsealSession as h3_unsealSession, | ||||||||||||||||||
| updateSession as h3_updateSession, | ||||||||||||||||||
| useSession as h3_useSession, | ||||||||||||||||||
| } from 'h3-v2' | ||||||||||||||||||
| } from 'h3' | ||||||||||||||||||
| import type { | ||||||||||||||||||
| RequestHeaderMap, | ||||||||||||||||||
| RequestHeaderName, | ||||||||||||||||||
|
|
@@ -147,7 +147,6 @@ export function getRequest(): Request { | |||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| export function getRequestHeaders(): TypedHeaders<RequestHeaderMap> { | ||||||||||||||||||
| // TODO `as any` not needed when fetchdts is updated | ||||||||||||||||||
| return getH3Event().req.headers as any | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
@@ -284,7 +283,16 @@ export function setResponseStatus(code?: number, text?: string): void { | |||||||||||||||||
| */ | ||||||||||||||||||
| export function getCookies(): Record<string, string> { | ||||||||||||||||||
| const event = getH3Event() | ||||||||||||||||||
| return h3_parseCookies(event) | ||||||||||||||||||
| const cookies = h3_parseCookies(event) | ||||||||||||||||||
| const normalizedCookies: Record<string, string> = {} | ||||||||||||||||||
|
|
||||||||||||||||||
| for (const [name, value] of Object.entries(cookies)) { | ||||||||||||||||||
| if (value !== undefined) { | ||||||||||||||||||
| normalizedCookies[name] = value | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| return normalizedCookies | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
|
|
@@ -296,7 +304,9 @@ export function getCookies(): Record<string, string> { | |||||||||||||||||
| * ``` | ||||||||||||||||||
| */ | ||||||||||||||||||
| export function getCookie(name: string): string | undefined { | ||||||||||||||||||
| return getCookies()[name] || undefined | ||||||||||||||||||
| const event = getH3Event() | ||||||||||||||||||
| const cookies = h3_parseCookies(event) | ||||||||||||||||||
| return cookies[name] || undefined | ||||||||||||||||||
|
Comment on lines
+307
to
+309
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # Check the file exists and view lines 307-309
wc -l packages/start-server-core/src/request-response.ts
sed -n '305,315p' packages/start-server-core/src/request-response.tsRepository: TanStack/router Length of output: 407 🏁 Script executed: # Let's also look for the getCookie function definition and context
sed -n '305,320p' packages/start-server-core/src/request-response.tsRepository: TanStack/router Length of output: 493 🏁 Script executed: # Search for where h3_parseCookies is imported from
rg "h3_parseCookies" packages/start-server-core/src/request-response.ts -B 5 -A 5Repository: TanStack/router Length of output: 1108 🏁 Script executed: # Check package.json to find h3 version
rg '"h3"' packages/start-server-core/package.jsonRepository: TanStack/router Length of output: 83 🏁 Script executed: # Search for any tests or usage examples of getCookie with empty values
rg "getCookie" packages/start-server-core --type ts -A 3 -B 1 | head -50Repository: TanStack/router Length of output: 1351 🏁 Script executed: # Check if there are any comments or documentation about cookie behavior
rg "cookie" packages/start-server-core/src/request-response.ts -i -B 2 -A 2Repository: TanStack/router Length of output: 3291 🏁 Script executed: # Search for tests related to getCookie function
find packages/start-server-core -name "*.test.*" -o -name "*.spec.*" | xargs rg "getCookie|cookie" 2>/dev/null | head -30Repository: TanStack/router Length of output: 41 🏁 Script executed: # Check if there's any TypeScript type definition or JSDoc for parseCookies
rg "parseCookies" --type ts -B 5 -A 10 | head -50Repository: TanStack/router Length of output: 3939 🌐 Web query:
💡 Result: In the h3 library (unjs/h3), the parseCookies(event) utility parses the Cookie header from the request and returns a Record<string, string> (object mapping cookie names to their values as strings). Cookie values are always strings, including empty strings ("") if the cookie was set with an empty value (e.g., name=; Path=/). This is standard behavior for Cookie header parsing using libraries like cookie (jshttp/cookie), which h3 relies on internally. TypeScript treats Record<string, string> as all values being non-nullable strings, so empty string values are fully compatible—no type errors occur. If no cookies are present, it returns {} (empty object), which is also valid. Examples from h3 docs and source: - parseCookies(event) → { cookieName: "cookieValue" } or { cookieName: "" } - getCookie(event, name) → string | undefined (wrapper around parseCookies) No issues or bugs reported specifically about empty string values in TypeScript context. If experiencing type mismatches, ensure proper typing: const cookies: Record<string, string> = parseCookies(event);. For source confirmation, early h3 versions used parse(req.headers.cookie || '') from 'cookie', returning Record<string, string>. Current versions maintain this signature per docs and utils pages. Citations:
Preserve empty cookie values in Line 309 uses Suggested fix export function getCookie(name: string): string | undefined {
const event = getH3Event()
const cookies = h3_parseCookies(event)
- return cookies[name] || undefined
+ return cookies[name]
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
|
|
||||||||||||||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.