diff --git a/site/content/docs/03-run-time.md b/site/content/docs/03-run-time.md index 2f351fee96..4f32ea682b 100644 --- a/site/content/docs/03-run-time.md +++ b/site/content/docs/03-run-time.md @@ -1082,3 +1082,22 @@ const { head, html, css } = App.render({ answer: 42 }); ``` + +You can call the `.render()` with the following parameters: + +| option | default | description | +| --- | --- | --- | +| `props` | `{}` | An object of properties to supply to the component +| `slots` | `{}` | A object of slots to supply to the component +| `context` | `new Map()` | A `Map` of context key-value pairs to supply to the component + +```js +const { head, html, css } = App.render( + // props + { answer: 42 }, + // slots + { 'slot-a': (lets) => 'hello world' }, + // contexts + new Map([['context-key', 'context-value']]), +); +``` \ No newline at end of file diff --git a/src/runtime/internal/ssr.ts b/src/runtime/internal/ssr.ts index 2d843abb2f..9ae49fc717 100644 --- a/src/runtime/internal/ssr.ts +++ b/src/runtime/internal/ssr.ts @@ -74,12 +74,12 @@ export function debug(file, line, column, values) { let on_destroy; export function create_ssr_component(fn) { - function $$render(result, props, bindings, slots) { + function $$render(result, props, bindings, slots, context) { const parent_component = current_component; const $$ = { on_destroy, - context: new Map(parent_component ? parent_component.$$.context : []), + context: new Map(parent_component ? parent_component.$$.context : context || []), // these will be immediately discarded on_mount: [], @@ -97,7 +97,7 @@ export function create_ssr_component(fn) { } return { - render: (props = {}, options = {}) => { + render: (props = {}, slots = {}, context = new Map()) => { on_destroy = []; const result: { @@ -109,7 +109,7 @@ export function create_ssr_component(fn) { }>; } = { title: '', head: '', css: new Set() }; - const html = $$render(result, props, {}, options); + const html = $$render(result, props, {}, slots, context); run_all(on_destroy); diff --git a/test/runtime/samples/constructor-pass-context/_config.js b/test/runtime/samples/constructor-pass-context/_config.js index 3348addf08..2e45032b1e 100644 --- a/test/runtime/samples/constructor-pass-context/_config.js +++ b/test/runtime/samples/constructor-pass-context/_config.js @@ -18,5 +18,15 @@ export default { assert.deepEqual(called, ['hello world']); component.$destroy(); + }, + test_ssr({ assert }) { + const Component = require('./Component.svelte').default; + + const called = []; + const { html } = Component.render(undefined, undefined, new Map([ + ['key', 'svelte'], + ['fn', (value) => called.push(value)] + ])); + assert.htmlEqual(html, '
svelte
'); } };