diff options
author | 2021-03-25 16:59:38 -0600 | |
---|---|---|
committer | 2021-03-25 16:59:38 -0600 | |
commit | 04a443a8887257e86d824bb22686a527f84c0875 (patch) | |
tree | b64a7cd8fa56e4c549a1b60afa63e611779eda53 /src/compiler/index.ts | |
parent | 3db595937719b89956c594e4a76ee68ae8de098a (diff) | |
download | astro-04a443a8887257e86d824bb22686a527f84c0875.tar.gz astro-04a443a8887257e86d824bb22686a527f84c0875.tar.zst astro-04a443a8887257e86d824bb22686a527f84c0875.zip |
Add React component SSR (#28)
* Add React component SSR
* Add React component SSR
Diffstat (limited to 'src/compiler/index.ts')
-rw-r--r-- | src/compiler/index.ts | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/compiler/index.ts b/src/compiler/index.ts index fea6b8a29..945d9bfc5 100644 --- a/src/compiler/index.ts +++ b/src/compiler/index.ts @@ -105,12 +105,11 @@ async function transformFromSource( } } - export async function compileComponent( source: string, { compileOptions = defaultCompileOptions, filename, projectRoot }: { compileOptions: CompileOptions; filename: string; projectRoot: string } ): Promise<CompileResult> { - const sourceJsx = await transformFromSource(source, { compileOptions, filename, projectRoot }); + const sourceJsx = await transformFromSource(source, { compileOptions, filename, projectRoot }); const isPage = path.extname(filename) === '.md' || sourceJsx.items.some((item) => item.name === 'html'); // sort <style> tags first sourceJsx.items.sort((a, b) => (a.name === 'style' && b.name !== 'style' ? -1 : 0)); @@ -124,9 +123,9 @@ ${sourceJsx.imports.join('\n')} // \`__render()\`: Render the contents of the Astro module. import { h, Fragment } from '${internalImport('h.js')}'; -async function __render(props, ...children) { +async function __render(props, ...children) { ${sourceJsx.script} - return h(Fragment, null, ${sourceJsx.items.map(({ jsx }) => jsx).join(',')}); + return h(Fragment, null, ${sourceJsx.items.map(({ jsx }) => jsx).join(',')}); } export default __render; `; @@ -134,9 +133,8 @@ export default __render; if (isPage) { modJsx += ` // \`__renderPage()\`: Render the contents of the Astro module as a page. This is a special flow, -// triggered by loading a component directly by URL. +// triggered by loading a component directly by URL. export async function __renderPage({request, children, props}) { - const currentChild = { setup: typeof setup === 'undefined' ? (passthrough) => passthrough : setup, layout: typeof __layout === 'undefined' ? undefined : __layout, @@ -155,7 +153,7 @@ export async function __renderPage({request, children, props}) { props: {content: currentChild.content}, children: [childBodyResult], }); - } + } return childBodyResult; };\n`; |