mirror of https://github.com/sveltejs/svelte
feat: more accurate `render`/`mount`/`hydrate` options (#12111)
make the props parameter optional only when there are no or only optional props --------- Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com> Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>nolyfill
parent
7295facb6c
commit
3da2646b10
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
feat: more accurate `render`/`mount`/`hydrate` options
|
@ -0,0 +1,21 @@
|
||||
import type { RenderOutput } from '#server';
|
||||
import type { ComponentProps, Component, SvelteComponent, ComponentType } from 'svelte';
|
||||
|
||||
/**
|
||||
* Only available on the server and when compiling with the `server` option.
|
||||
* Takes a component and returns an object with `body` and `head` properties on it, which you can use to populate the HTML when server-rendering your app.
|
||||
*/
|
||||
export function render<
|
||||
Comp extends SvelteComponent<any> | Component<any>,
|
||||
Props extends ComponentProps<Comp> = ComponentProps<Comp>
|
||||
>(
|
||||
...args: {} extends Props
|
||||
? [
|
||||
component: Comp extends SvelteComponent<any> ? ComponentType<Comp> : Comp,
|
||||
options?: { props?: Omit<Props, '$$slots' | '$$events'>; context?: Map<any, any> }
|
||||
]
|
||||
: [
|
||||
component: Comp extends SvelteComponent<any> ? ComponentType<Comp> : Comp,
|
||||
options: { props: Omit<Props, '$$slots' | '$$events'>; context?: Map<any, any> }
|
||||
]
|
||||
): RenderOutput;
|
@ -1,7 +1,5 @@
|
||||
// @ts-ignore
|
||||
import { render } from 'svelte/server';
|
||||
// @ts-ignore you need to create this file
|
||||
import App from './App.svelte';
|
||||
|
||||
// @ts-ignore
|
||||
export const { head, body, css } = render(App, { props: { initialCount: 0 } });
|
||||
export const { head, body } = render(App);
|
||||
|
Loading…
Reference in new issue