set() — astro Function Reference
Architecture documentation for the set() function in cookies.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 1eca20ec_d5f5_80f3_2ce1_84641921b4ed["set()"] 28935751_f2b1_4797_d41a_fc616c40e0a8["AstroCookies"] 1eca20ec_d5f5_80f3_2ce1_84641921b4ed -->|defined in| 28935751_f2b1_4797_d41a_fc616c40e0a8 334ca8ee_5039_a932_680a_7755acc78324["delete()"] 334ca8ee_5039_a932_680a_7755acc78324 -->|calls| 1eca20ec_d5f5_80f3_2ce1_84641921b4ed c8875d28_14c6_0b92_021c_fcc01ea915ac["merge()"] c8875d28_14c6_0b92_021c_fcc01ea915ac -->|calls| 1eca20ec_d5f5_80f3_2ce1_84641921b4ed style 1eca20ec_d5f5_80f3_2ce1_84641921b4ed fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/astro/src/core/cookies/cookies.ts lines 174–214
set(key: string, value: string | Record<string, any>, options?: AstroCookieSetOptions): void {
if (this.#consumed) {
const warning = new Error(
'Astro.cookies.set() was called after the cookies had already been sent to the browser.\n' +
'This may have happened if this method was called in an imported component.\n' +
'Please make sure that Astro.cookies.set() is only called in the frontmatter of the main page.',
);
warning.name = 'Warning';
console.warn(warning);
}
let serializedValue: string;
if (typeof value === 'string') {
serializedValue = value;
} else {
// Support stringifying JSON objects for convenience. First check that this is
// a plain object and if it is, stringify. If not, allow support for toString() overrides.
let toStringValue = value.toString();
if (toStringValue === Object.prototype.toString.call(value)) {
serializedValue = JSON.stringify(value);
} else {
serializedValue = toStringValue;
}
}
const serializeOptions: SerializeOptions = {};
if (options) {
Object.assign(serializeOptions, options);
}
this.#ensureOutgoingMap().set(key, [
serializedValue,
serialize(key, serializedValue, serializeOptions),
true,
]);
if ((this.#request as any)[responseSentSymbol]) {
throw new AstroError({
...AstroErrorData.ResponseSentError,
});
}
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does set() do?
set() is a function in the astro codebase, defined in packages/astro/src/core/cookies/cookies.ts.
Where is set() defined?
set() is defined in packages/astro/src/core/cookies/cookies.ts at line 174.
What calls set()?
set() is called by 2 function(s): delete, merge.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free