Fix: Astro.props missing properties (#2785)

* Fix: Astro.props missing properties

* chore: add changeset
This commit is contained in:
Ben Holmes 2022-03-14 13:03:44 -04:00 committed by GitHub
parent 77e5733deb
commit 2c4fd919fa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View 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

View file

@ -44,9 +44,11 @@ export async function getParamsAndProps(opts: GetParamsAndPropsOptions): Promise
if (!matchedStaticPath) { if (!matchedStaticPath) {
return GetParamsAndPropsError.NoMatchingStaticPath; return GetParamsAndPropsError.NoMatchingStaticPath;
} }
// This is written this way for performance; instead of spreading the props // Note: considered using Object.create(...) for performance
// which is O(n), create a new object that extends props. // Since this doesn't inherit an object's properties, this caused some odd user-facing behavior.
pageProps = Object.create(matchedStaticPath.props || Object.prototype); // 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 { } else {
pageProps = {}; pageProps = {};
} }