Skip to content

handleCors() returns falsy sentinel (""), conflicting with example usage. #1166

@jakobrosenberg

Description

@jakobrosenberg

Environment

h3: 2.0.0-beta.1

Reproduction

Simply check the declared type:

declare function handleCors(event: H3Event, options: CorsOptions): false | "";

Describe the bug

Description:
handleCors() returns an empty string ("") when handling preflight requests. However, the official example suggests using a truthy check (if (corsRes)), which fails since "" is falsy. This makes the example incorrect and the API unintuitive.

Expected:
Return a truthy sentinel (e.g. true or "handled") to indicate preflight handled, matching the example pattern.

Actual:
Returns falsy sentinel (""), making:

if (corsRes) return corsRes

ineffective.

Additional context

No response

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions