Skip to content

Commit

Permalink
Fixes bug where Astro can't distinguish between two equal components …
Browse files Browse the repository at this point in the history
…differing only by props when hydrating (#846)
  • Loading branch information
matsdahlin authored Jul 27, 2021
1 parent bef5103 commit e89a99f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/chilly-gorillas-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

This includes the props passed to a hydration component when generating the hash/id. This prevents multiple instances of the same component with differing props to be treated as the same component when hydrated by Astro.
3 changes: 2 additions & 1 deletion packages/astro/src/internal/__astro_component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ export function __astro_component(Component: any, metadata: AstroComponentMetada
}

// If we ARE hydrating this component, let's generate the hydration script
const astroId = hash.unique(html);
const stringifiedProps = JSON.stringify(props);
const astroId = hash.unique(html + stringifiedProps);
const script = await generateHydrateScript({ instance, astroId, props }, metadata as Required<AstroComponentMetadata>);
const astroRoot = `<astro-root uid="${astroId}">${html}</astro-root>`;
return [astroRoot, script].join('\n');
Expand Down

1 comment on commit e89a99f

@vercel
Copy link

@vercel vercel bot commented on e89a99f Jul 27, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.