Skip to content

Commit

Permalink
fix: fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
aralroca committed Mar 22, 2024
1 parent b20e1bd commit a0173a2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 27 deletions.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,8 @@ import { dangerHTML } from "brisa";
import { renderToString } from "brisa/server";

export const prerenderConfig = {
render: (Component, props) => {
return renderToString(<Component {...props} />);
},
postRender: dangerHTML,
render: async (Component: any, props: any) =>
dangerHTML(await renderToString(<Component {...props} />)),
};

export const plugin = prerenderMacroPlugin({
Expand Down Expand Up @@ -234,11 +232,12 @@ import { h } from "preact";

export const prerenderConfig = {
render: async (Component: any, props: any) => {
return render(<Component {...props} />);
return (
<div
dangerouslySetInnerHTML={{ __html: render(<Component {...props} />) }}
/>
);
},
postRender: (htmlString: string) => (
<div dangerouslySetInnerHTML={{ __html: htmlString }} />
),
};

export const plugin = prerenderMacroPlugin({
Expand Down
3 changes: 1 addition & 2 deletions examples-and-tests/brisa/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ import { renderToString } from "brisa/server";

export const prerenderConfig = {
render: async (Component: any, props: any) =>
renderToString(<Component {...props} />),
postRender: dangerHTML,
dangerHTML(await renderToString(<Component {...props} />)),
};
9 changes: 5 additions & 4 deletions examples-and-tests/preact/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { h } from "preact";

export const prerenderConfig = {
render: async (Component: any, props: any) => {
return render(<Component {...props} />);
return (
<div
dangerouslySetInnerHTML={{ __html: render(<Component {...props} />) }}
/>
);
},
postRender: (htmlString: string) => (
<div dangerouslySetInnerHTML={{ __html: htmlString }} />
),
};
11 changes: 4 additions & 7 deletions examples-and-tests/preact/plugin.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ describe("Preact", () => {
children: [{type: "div",props: {
dangerouslySetInnerHTML: {__html: "<div>Foo, foo!</div>"
}},
__k: null,__: null,__b: 0,__e: null,__c: null,__v: 4,__i: -1,__u: 0},
jsxDEV(Bar, {}, undefined, false, undefined, this)]}, undefined, true, undefined, this);
key: undefined,ref: undefined,__k: null,__: null,__b: 0,__e: null,__d: undefined,__c: null,constructor: undefined,__v: 4,__i: -1,__u: 0},jsxDEV(Bar, {}, undefined, false, undefined, this)]}, undefined, true, undefined, this);
}
`);

Expand Down Expand Up @@ -84,9 +83,7 @@ describe("Preact", () => {
type: "div",props: {dangerouslySetInnerHTML: {
__html: "<div>Bar, bar!</div>"
}
},
__k: null,__: null,__b: 0,__e: null,__c: null,__v: 8,__i: -1,__u: 0}]
}, undefined, true, undefined, this);
},key: undefined,ref: undefined,__k: null,__: null,__b: 0,__e: null,__d: undefined,__c: null,constructor: undefined,__v: 8,__i: -1,__u: 0}]}, undefined, true, undefined, this);
}
`);

Expand All @@ -106,7 +103,7 @@ describe("Preact", () => {
import {Bar} from "./components";
export default function Test() {
return {type: "div",props: {dangerouslySetInnerHTML: {__html: "<div>Bar, bar!</div>"}},__k: null,__: null,__b: 0,__e: null,__c: null,__v: 12,__i: -1,__u: 0};
return {type: "div",props: {dangerouslySetInnerHTML: {__html: "<div>Bar, bar!</div>"}},key: undefined,ref: undefined,__k: null,__: null,__b: 0,__e: null,__d: undefined,__c: null,constructor: undefined,__v: 12,__i: -1,__u: 0};
}
`);

Expand All @@ -126,7 +123,7 @@ describe("Preact", () => {
import Foo from "./components";
export default function Test() {
return {type: "div",props: {dangerouslySetInnerHTML: {__html: "<div>Foo, Preact works!</div>"}},__k: null,__: null,__b: 0,__e: null,__c: null,__v: 16,__i: -1,__u: 0};
return {type: "div",props: {dangerouslySetInnerHTML: {__html: "<div>Foo, Preact works!</div>"}},key: undefined,ref: undefined,__k: null,__: null,__b: 0,__e: null,__d: undefined,__c: null,constructor: undefined,__v: 16,__i: -1,__u: 0};
}
`);

Expand Down
7 changes: 1 addition & 6 deletions package/prerender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ export async function prerender({
}: PrerenderParams) {
const Component = (await import(componentPath))[componentModuleName];
const config = (await import(prerenderConfigPath)).prerenderConfig;
const htmlString = await config.render(Component, componentProps);

const element = config.postRender(htmlString);

// parse + stringify are used to avoid coercion to Bun's AST for $$typeof Symbol
return JSON.parse(JSON.stringify(element));
return await config.render(Component, componentProps);
}

export function postRender(element: JSX.Element) {
Expand Down

0 comments on commit a0173a2

Please sign in to comment.