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

Prevent removal of nested slots within islands #7093

Merged
merged 3 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix build errors
  • Loading branch information
matthewp committed May 15, 2023
commit 4b95be0705d43ac61c051187cbe41891c677bf2b
10 changes: 5 additions & 5 deletions packages/integrations/preact/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const slotName = (str: string) => str.trim().replace(/[-_]([a-z])/g, (_, w) => w
let originalConsoleError: typeof console.error;
let consoleFilterRefs = 0;

function check(this: RendererContext, Component: any, props: Record<string, any>, children: any) {
function check(this: RendererContext, Component: any, props: Record<string, any>, children: any, ) {
if (typeof Component !== 'function') return false;

if (Component.prototype != null && typeof Component.prototype.render === 'function') {
Expand All @@ -22,7 +22,7 @@ function check(this: RendererContext, Component: any, props: Record<string, any>

try {
try {
const { html } = renderToStaticMarkup.call(this, Component, props, children);
const { html } = renderToStaticMarkup.call(this, Component, props, children, undefined);
if (typeof html !== 'string') {
return false;
}
Expand All @@ -39,17 +39,17 @@ function check(this: RendererContext, Component: any, props: Record<string, any>
}
}

function shouldHydrate(metadata: AstroMetadata) {
function shouldHydrate(metadata: AstroComponentMetadata | undefined) {
// Adjust how this is hydrated only when the version of Astro supports `astroStaticSlot`
return metadata.astroStaticSlot ? !!metadata.hydrate : true;
return metadata?.astroStaticSlot ? !!metadata.hydrate : true;
}

function renderToStaticMarkup(
this: RendererContext,
Component: any,
props: Record<string, any>,
{ default: children, ...slotted }: Record<string, any>,
metadata: AstroMetadata,
metadata: AstroComponentMetadata | undefined,
) {
const ctx = getContext(this.result);

Expand Down
4 changes: 2 additions & 2 deletions packages/integrations/preact/src/static-html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { h } from 'preact';
type Props = {
value: string;
name?: string;
hydrate: boolean;
hydrate?: boolean;
}

/**
Expand All @@ -15,7 +15,7 @@ type Props = {
*/
const StaticHtml = ({ value, name, hydrate }: Props) => {
if (!value) return null;
const tagName = hydrate ? 'astro-slot' : 'astro-static-slot';
const tagName = hydrate === false ? 'astro-static-slot' : 'astro-slot';
return h(tagName, { name, dangerouslySetInnerHTML: { __html: value } });
};

Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/solid/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function renderToStaticMarkup(
metadata?: undefined | Record<string, any>
) {
const renderId = metadata?.hydrate ? incrementId(getContext(this.result)) : '';
const needsHydrate = metadata.astroStaticSlot ? !!metadata.hydrate : true;
const needsHydrate = metadata?.astroStaticSlot ? !!metadata.hydrate : true;
const tagName = needsHydrate ? 'astro-slot' : 'astro-static-slot';

const html = renderToString(
Expand Down