From 2c4fd919faa887df659d756ed3d095e0e83ed87d Mon Sep 17 00:00:00 2001 From: Ben Holmes Date: Mon, 14 Mar 2022 13:03:44 -0400 Subject: [PATCH] Fix: Astro.props missing properties (#2785) * Fix: Astro.props missing properties * chore: add changeset --- .changeset/nice-tables-applaud.md | 5 +++++ packages/astro/src/core/render/core.ts | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 .changeset/nice-tables-applaud.md 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 = {}; }