Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check null for props serialization #3657

Merged
merged 2 commits into from
Jun 21, 2022
Merged

Conversation

leaysgur
Copy link
Contributor

@leaysgur leaysgur commented Jun 21, 2022

Changes

Fixes #3641

Currently, astro build fails with client-hydrated-component like below.

---
import Counter from '../components/Counter.tsx';
---
<html lang="en">
	<head>
		<meta charset="utf-8" />
	</head>
	<body>
		<main>
			<Counter client:visible data={{ x: null }} />
		</main>
	</body>
</html>

Because typeof null === object,

default: {
if (typeof value === 'object') {
return [PROP_TYPE.Value, serializeObject(value)];

and Object.entries(null) throws.

function serializeObject(value: Record<any, any>): Record<any, any> {
return Object.fromEntries(
Object.entries(value).map(([k, v]) => {
return [k, convertToSerializedForm(v)];
})
);
}


Previously(#3571), serialize-javascript had covered this scenario.

Testing

I'd like to add some tests, but where should it be placed...?

Docs

Nothing changed.

@changeset-bot
Copy link

changeset-bot bot commented Jun 21, 2022

🦋 Changeset detected

Latest commit: 3c83d8b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
astro Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jun 21, 2022
@natemoo-re natemoo-re requested a review from matthewp June 21, 2022 13:38
Copy link
Member

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for the fix!

@natemoo-re natemoo-re merged commit 7d4699b into withastro:main Jun 21, 2022
@github-actions github-actions bot mentioned this pull request Jun 21, 2022
@leaysgur leaysgur deleted the patch-1 branch June 21, 2022 22:13
SiriousHunter pushed a commit to SiriousHunter/astro that referenced this pull request Feb 3, 2023
* Check null for props serialization

* Add changeset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 BUG: Cannot convert undefined or null to object in beta 47
2 participants