You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cacheKey generated an incorrect value in incremental static builds. #17635
- P2: has workaroundAn edge case that only affects very specific usage, but has a trivial workaround (priority)pkg: astroRelated to the core `astro` package (scope)triage: unable to fixBug reproduced and diagnosed, but no fix was found
Unit Test: No — this is a user code issue, not an Astro bug
Priority:P2: has workaround. This is not an Astro bug — the [object Object] value originates from the reporter's own code. The workaround is to use JSON.stringify() or a proper hash instead of String() when serializing complex objects for cacheKey.
The [object Object] cacheKey value comes from your own code in src/pages/[magazine]/[slug].astro, where you write cacheKey: String(entry.data.sections). JavaScript's String() on an array of objects produces \"[object Object],[object Object]\" — it does not serialize the contents. By the time Astro receives this value, it's already a meaningless string. The cacheKey API expects a string | number (like entry.digest), and Astro's internal handling works correctly for those types.
I wasn't able to find a fix, but I identified some areas that may be relevant. The immediate fix is in your project code — replace String(entry.data.sections) with JSON.stringify(entry.data.sections) (or better yet, compute a hash of your data). Astro could improve DX here by adding a runtime warning when a cacheKey contains [object Object] — the relevant code is in packages/astro/src/runtime/prerender/static-paths.ts line 123.
Full Triage Report
Issue Details
Title: cacheKey generated an incorrect value in incremental static builds.
Reporter: sgalcheung
Environment:
Astro v7.2.0
Node v22.16.0
macOS (x64)
pnpm
Output: static
Integration: @astrojs/starlight
Description: When using experimental.incrementalBuild: true, the cacheKey stored in the incremental build cache manifest (incremental-build.json) is \"[object Object]\" or \"[object Object], [object Object]\" instead of a proper hash or meaningful string value.
Reproduction
Created a minimal project with experimental.incrementalBuild: true and a dynamic route returning object values as cacheKey. The incremental build cache showed:
With proper string cacheKeys (e.g. 'post-1-v1'), the cache stores correct values.
Root Cause
The reporter's code in src/pages/[magazine]/[slug].astro:
cacheKey: String(entry.data.sections),
Where entry.data.sections is z.array(z.object({...})). String() on an array of objects produces \"[object Object],[object Object]\". This is a JavaScript behavior — String() does not serialize object contents.
Astro's internal String() coercion in packages/astro/src/runtime/prerender/static-paths.ts line 123 is designed to normalize string | number → string, which works correctly for the documented input types. The cacheKey TypeScript type is string | number (defined in packages/astro/src/types/public/common.ts:18), and the documented usage is cacheKey: post.digest (a string hash).
Verdict: Intended Behavior (User Error)
Confidence: high
The [object Object] value is produced by the reporter's own String() call, not by Astro. The API contract (string | number) is correctly defined and documented. The fix is to use JSON.stringify(entry.data.sections) or compute a proper hash.
Enhancement opportunity: Astro could add a runtime warning when cacheKey contains [object Object], helping users catch this common serialization mistake. The relevant validation gap is in packages/astro/src/core/routing/validation.ts (validates params but not cacheKey).
This report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue."
If the cacheKey is an object type, this will return [object Object]; this will never change it.
I think the key point is whether we should handle different types for cacheKey. And finally, should this cacheKey be converted to a hash value?
Do you mean cacheKey only accepts strings or numbers? why? I think in this case, a hash string would be better.
I have some reasons here:
Users only need to care about semantics, not implementation details.
The essence of cacheKey is "the data version/identifier corresponding to this static path," not "a pre-hashable string."
Users can pass any structured data (objects, arrays, numbers, strings, etc.).
Internally, it is uniformly converted into a stable hash, avoiding the need for users to implement serialization/encryption themselves.
This makes the API more intuitive: cacheKey is a "value," not a "hash value."
Guaranteeing consistency and stability.
If the hash logic were left to the user, many variations would occur:
Some users would directly pass strings.
Some users would implement their own JSON.stringify.
Some users would use different hash algorithms.
Some users would pass objects but without proper processing order. Internal processing ensures:
The same input always generates the same hash.
Cache conflicts or misses will not occur due to different user implementations.
The same rules do not need to be implemented repeatedly in every integration.
Reducing the risk of disruptive changes. Now, by handling hashes internally, the algorithm and format can be encapsulated within the framework.
If we change it to "users must provide their own hash," then we'll need to:
Expand the current hash algorithm
Commit compatibility
Or force users to adapt individually.
This exposes internal implementation details as a public contract, increasing maintenance burden.
Prevent users from inputting unhashable/insecure values.
Currently, cacheKey is unknown, meaning users might pass:
Ensuring this value is safe and comparable within the internal cache.
Better aligns with the design principle of "framework responsible for behavioral consistency."
For internal caching mechanisms like prerender/incremental static builds, the framework itself is responsible for:
Generating unique and stable cache keys
Performing cache reuse based on the same semantics
Managing consistency in the compilation pipeline. Leaving this part to the user forces them to bear the responsibility of "cache correctness," which should be the framework's responsibility.
Closing as this is based on a misunderstanding. The cacheKey is set by the user and is expected to be unique. It's up to each application to determine which key to use. Closing.
- P2: has workaroundAn edge case that only affects very specific usage, but has a trivial workaround (priority)pkg: astroRelated to the core `astro` package (scope)triage: unable to fixBug reproduced and diagnosed, but no fix was found
Activity
astrobot-houston commentedon Aug 8, 2026
[object Object]value originates from the reporter's own code. The workaround is to useJSON.stringify()or a proper hash instead ofString()when serializing complex objects forcacheKey.The
[object Object]cacheKey value comes from your own code insrc/pages/[magazine]/[slug].astro, where you writecacheKey: String(entry.data.sections). JavaScript'sString()on an array of objects produces\"[object Object],[object Object]\"— it does not serialize the contents. By the time Astro receives this value, it's already a meaningless string. ThecacheKeyAPI expects astring | number(likeentry.digest), and Astro's internal handling works correctly for those types.I wasn't able to find a fix, but I identified some areas that may be relevant. The immediate fix is in your project code — replace
String(entry.data.sections)withJSON.stringify(entry.data.sections)(or better yet, compute a hash of your data). Astro could improve DX here by adding a runtime warning when acacheKeycontains[object Object]— the relevant code is inpackages/astro/src/runtime/prerender/static-paths.tsline 123.Full Triage Report
Issue Details
Title: cacheKey generated an incorrect value in incremental static builds.
Reporter: sgalcheung
Environment:
Description: When using
experimental.incrementalBuild: true, thecacheKeystored in the incremental build cache manifest (incremental-build.json) is\"[object Object]\"or\"[object Object], [object Object]\"instead of a proper hash or meaningful string value.Reproduction
Created a minimal project with
experimental.incrementalBuild: trueand a dynamic route returning object values ascacheKey. The incremental build cache showed:{ \"paths\": { \"/posts/post-1\": { \"cacheKey\": \"[object Object]\", \"outputFile\": \"posts/post-1/index.html\" }, \"/posts/post-2\": { \"cacheKey\": \"[object Object],[object Object]\", \"outputFile\": \"posts/post-2/index.html\" } } }With proper string cacheKeys (e.g.
'post-1-v1'), the cache stores correct values.Root Cause
The reporter's code in
src/pages/[magazine]/[slug].astro:Where
entry.data.sectionsisz.array(z.object({...})).String()on an array of objects produces\"[object Object],[object Object]\". This is a JavaScript behavior —String()does not serialize object contents.Astro's internal
String()coercion inpackages/astro/src/runtime/prerender/static-paths.tsline 123 is designed to normalizestring | number→string, which works correctly for the documented input types. ThecacheKeyTypeScript type isstring | number(defined inpackages/astro/src/types/public/common.ts:18), and the documented usage iscacheKey: post.digest(a string hash).Verdict: Intended Behavior (User Error)
Confidence: high
The
[object Object]value is produced by the reporter's ownString()call, not by Astro. The API contract (string | number) is correctly defined and documented. The fix is to useJSON.stringify(entry.data.sections)or compute a proper hash.Enhancement opportunity: Astro could add a runtime warning when
cacheKeycontains[object Object], helping users catch this common serialization mistake. The relevant validation gap is inpackages/astro/src/core/routing/validation.ts(validatesparamsbut notcacheKey).This report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue."
matthewp commentedon Aug 8, 2026
It doesn't have to be a hash. Just any distinct string, it depends on your data.
sgalcheung commentedon Aug 8, 2026
OK, I won't change the type of cacheKey; I just want to be clear: it is a hash string.
sgalcheung commentedon Aug 8, 2026
astro/packages/astro/src/runtime/prerender/static-paths.ts
Line 123 in 7c4bf1b
This cacheKey should handle a hash, not a string?
matthewp commentedon Aug 8, 2026
Any string. The user application provides
cacheKey, Astro doesn't create it internally.sgalcheung commentedon Aug 8, 2026
If the
cacheKeyis an object type, this will return[object Object]; this will never change it.I think the key point is whether we should handle different types for
cacheKey. And finally, should thiscacheKeybe converted to a hash value?wildfiremedia commentedon Aug 9, 2026
cacheKeyshould stay string | number only. Accepting objects is basically inviting an[object Object]objection from every unwitting dev's build log.sgalcheung commentedon Aug 9, 2026
Hi, @wildfiremedia, I moved some discussion in the general channel to a Thread in Discord(https://discord.com/channels/830184174198718474/1535882518660653116); you can see this!
wildfiremedia commentedon Aug 9, 2026
@sgalcheung Yeah, read that when you first posted in Discord.
matthewp commentedon Aug 10, 2026
@sgalcheung Yeah agreed, would accept a PR to limit the type to just those two.
sgalcheung commentedon Aug 11, 2026
Do you mean cacheKey only accepts strings or numbers? why? I think in this case, a hash string would be better.
I have some reasons here:
The essence of
cacheKeyis "the data version/identifier corresponding to this static path," not "a pre-hashable string."Users can pass any structured data (objects, arrays, numbers, strings, etc.).
Internally, it is uniformly converted into a stable hash, avoiding the need for users to implement serialization/encryption themselves.
This makes the API more intuitive:
cacheKeyis a "value," not a "hash value."If the hash logic were left to the user, many variations would occur:
Some users would directly pass strings.
Some users would implement their own
JSON.stringify.Some users would use different hash algorithms.
Some users would pass objects but without proper processing order. Internal processing ensures:
The same input always generates the same hash.
Cache conflicts or misses will not occur due to different user implementations.
The same rules do not need to be implemented repeatedly in every integration.
If we change it to "users must provide their own hash," then we'll need to:
Expand the current hash algorithm
Commit compatibility
Or force users to adapt individually.
This exposes internal implementation details as a public contract, increasing maintenance burden.
Currently,
cacheKeyisunknown, meaning users might pass:Objects
Containing functions
Nested structures
Non-standard values. Internal processing can uniformly handle this:
deterministicString(cacheKey)SHA-256generateContentHashEnsuring this value is safe and comparable within the internal cache.
For internal caching mechanisms like prerender/incremental static builds, the framework itself is responsible for:
Generating unique and stable cache keys
Performing cache reuse based on the same semantics
Managing consistency in the compilation pipeline. Leaving this part to the user forces them to bear the responsibility of "cache correctness," which should be the framework's responsibility.
matthewp commentedon Aug 12, 2026
Closing as this is based on a misunderstanding. The
cacheKeyis set by the user and is expected to be unique. It's up to each application to determine which key to use. Closing.