diff options
author | 2022-03-14 13:03:44 -0400 | |
---|---|---|
committer | 2022-03-14 13:03:44 -0400 | |
commit | 2c4fd919faa887df659d756ed3d095e0e83ed87d (patch) | |
tree | 2db07eeecc9465c545b93e6d4cf8bc6c8c5768e0 | |
parent | 77e5733deb1354a65f63bb6134e1f5234ff02f4e (diff) | |
download | astro-2c4fd919faa887df659d756ed3d095e0e83ed87d.tar.gz astro-2c4fd919faa887df659d756ed3d095e0e83ed87d.tar.zst astro-2c4fd919faa887df659d756ed3d095e0e83ed87d.zip |
Fix: Astro.props missing properties (#2785)
* Fix: Astro.props missing properties
* chore: add changeset
-rw-r--r-- | .changeset/nice-tables-applaud.md | 5 | ||||
-rw-r--r-- | packages/astro/src/core/render/core.ts | 8 |
2 files changed, 10 insertions, 3 deletions
diff --git a/.changeset/nice-tables-applaud.md b/.changeset/nice-tables-applaud.md new file mode 100644 index 000000000..f73b31891 --- /dev/null +++ b/.changeset/nice-tables-applaud.md @@ -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 diff --git a/packages/astro/src/core/render/core.ts b/packages/astro/src/core/render/core.ts index 32493ead1..ccea0c743 100644 --- a/packages/astro/src/core/render/core.ts +++ b/packages/astro/src/core/render/core.ts @@ -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 = {}; } |