Fix: Astro.props missing properties (#2785)
* Fix: Astro.props missing properties * chore: add changeset
This commit is contained in:
parent
77e5733deb
commit
2c4fd919fa
2 changed files with 10 additions and 3 deletions
5
.changeset/nice-tables-applaud.md
Normal file
5
.changeset/nice-tables-applaud.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Update Astro.props to show object properties on console.log(Astro.props), interating over properties, and anything else outside direct key access
|
|
@ -44,9 +44,11 @@ export async function getParamsAndProps(opts: GetParamsAndPropsOptions): Promise
|
|||
if (!matchedStaticPath) {
|
||||
return GetParamsAndPropsError.NoMatchingStaticPath;
|
||||
}
|
||||
// This is written this way for performance; instead of spreading the props
|
||||
// which is O(n), create a new object that extends props.
|
||||
pageProps = Object.create(matchedStaticPath.props || Object.prototype);
|
||||
// Note: considered using Object.create(...) for performance
|
||||
// Since this doesn't inherit an object's properties, this caused some odd user-facing behavior.
|
||||
// Ex. console.log(Astro.props) -> {}, but console.log(Astro.props.property) -> 'expected value'
|
||||
// Replaced with a simple spread as a compromise
|
||||
pageProps = matchedStaticPath.props ? { ...matchedStaticPath.props } : {};
|
||||
} else {
|
||||
pageProps = {};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue