Skip to content

Document default values in cookies options#72183

Merged
ijjk merged 3 commits intovercel:canaryfrom
karlhorky:patch-2
Nov 1, 2024
Merged

Document default values in cookies options#72183
ijjk merged 3 commits intovercel:canaryfrom
karlhorky:patch-2

Conversation

@karlhorky
Copy link
Copy Markdown
Contributor

@karlhorky karlhorky commented Nov 1, 2024

What?

Document the default values for cookies, eg. used in cookies().set(), fix typo

Why?

Default values are undocumented (probably because there are almost no default values)

Screenshot 2024-11-01 at 16 20 57

How?

  1. Add a default annotation in the options table row for path, based on the packages/next/src/compiled/@edge-runtime/cookies/index.js code:
    function normalizeCookie(cookie = { name: "", value: "" }) {
    if (typeof cookie.expires === "number") {
    cookie.expires = new Date(cookie.expires);
    }
    if (cookie.maxAge) {
    cookie.expires = new Date(Date.now() + cookie.maxAge * 1e3);
    }
    if (cookie.path === null || cookie.path === void 0) {
    cookie.path = "/";
    }
    return cookie;
    }
  2. Add a short paragraph about other options not having default values
  3. Fix the extra , typo

@ijjk ijjk added the Documentation Related to Next.js' official documentation. label Nov 1, 2024
@ijjk
Copy link
Copy Markdown
Member

ijjk commented Nov 1, 2024

Allow CI Workflow Run

  • approve CI run for commit: 9e59ef1

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@ijjk ijjk enabled auto-merge (squash) November 1, 2024 17:43
@ijjk ijjk merged commit 53c631e into vercel:canary Nov 1, 2024
@karlhorky
Copy link
Copy Markdown
Contributor Author

@ijjk thanks for the review and merge!

@karlhorky karlhorky deleted the patch-2 branch November 1, 2024 21:56
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Documentation Related to Next.js' official documentation. locked

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants