Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/olive-jars-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': minor
---

feat: export `RenderOutput`, `SyncRenderOutput`, `Csp` and `Sha256Source` from `svelte/server`
2 changes: 1 addition & 1 deletion packages/svelte/src/internal/server/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @import { ComponentType, SvelteComponent, Component } from 'svelte' */
/** @import { Csp, RenderOutput } from '#server' */
/** @import { Csp, RenderOutput } from '../../server/public.js' */
/** @import { Store } from '#shared' */
export { FILENAME, HMR } from '../../constants.js';
import { attr, clsx, to_class, to_style } from '../shared/attributes.js';
Expand Down
3 changes: 2 additions & 1 deletion packages/svelte/src/internal/server/renderer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @import { Component } from 'svelte' */
/** @import { Csp, HydratableContext, RenderOutput, SSRContext, SyncRenderOutput, Sha256Source } from './types.js' */
/** @import { HydratableContext, SSRContext } from './types.js' */
/** @import { Csp, RenderOutput, SyncRenderOutput, Sha256Source } from '../../server/public.js' */
/** @import { MaybePromise } from '#shared' */
import { async_mode_flag } from '../flags/index.js';
import { abort } from './abort-signal.js';
Expand Down
18 changes: 0 additions & 18 deletions packages/svelte/src/internal/server/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export interface SSRContext {
element?: Element;
}

export type Csp = { nonce?: string; hash?: boolean };

export interface HydratableLookupEntry {
value: unknown;
serialized: string;
Expand All @@ -34,19 +32,3 @@ export interface HydratableContext {
export interface RenderContext {
hydratable: HydratableContext;
}

export type Sha256Source = `sha256-${string}`;

export interface SyncRenderOutput {
/** HTML that goes into the `<head>` */
head: string;
/** @deprecated use `body` instead */
html: string;
/** HTML that goes somewhere into the `<body>` */
body: string;
hashes: {
script: Sha256Source[];
};
}

export type RenderOutput = SyncRenderOutput & PromiseLike<SyncRenderOutput>;
2 changes: 1 addition & 1 deletion packages/svelte/src/legacy/legacy-server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @import { SvelteComponent } from '../index.js' */
/** @import { Csp } from '#server' */
/** @import { Csp } from '../server/public.js' */
import { asClassComponent as as_class_component, createClassComponent } from './legacy-client.js';
import { render } from '../internal/server/index.js';
import { async_mode_flag } from '../internal/flags/index.js';
Expand Down
4 changes: 3 additions & 1 deletion packages/svelte/src/server/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { Csp, RenderOutput } from '#server';
import type { Csp, RenderOutput } from './public.js';
import type { ComponentProps, Component, SvelteComponent, ComponentType } from 'svelte';

export type { Csp, RenderOutput, SyncRenderOutput, Sha256Source } from './public.js';

/**
* 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.
Expand Down
17 changes: 17 additions & 0 deletions packages/svelte/src/server/public.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export type Csp = { nonce?: string; hash?: boolean };

export type Sha256Source = `sha256-${string}`;

export interface SyncRenderOutput {
/** HTML that goes into the `<head>` */
head: string;
/** @deprecated use `body` instead */
html: string;
/** HTML that goes somewhere into the `<body>` */
body: string;
hashes: {
script: Sha256Source[];
};
}

export type RenderOutput = SyncRenderOutput & PromiseLike<SyncRenderOutput>;
3 changes: 1 addition & 2 deletions packages/svelte/tests/server-side-rendering/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@

import * as fs from 'node:fs';
import { assert } from 'vitest';
import { render } from 'svelte/server';
import { render, type SyncRenderOutput } from 'svelte/server';
import { compile_directory, should_update_expected, try_read_file } from '../helpers.js';
import { assert_html_equal_with_options } from '../html_equal.js';
import { suite_with_variants, type BaseTest } from '../suite.js';
import type { CompileOptions } from '#compiler';
import { seen } from '../../src/internal/server/dev.js';
import type { SyncRenderOutput } from '#server';

interface SSRTest extends BaseTest {
mode?: ('sync' | 'async')[];
Expand Down
8 changes: 4 additions & 4 deletions packages/svelte/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2612,11 +2612,11 @@ declare module 'svelte/server' {
}
]
): RenderOutput;
type Csp = { nonce?: string; hash?: boolean };
export type Csp = { nonce?: string; hash?: boolean };

type Sha256Source = `sha256-${string}`;
export type Sha256Source = `sha256-${string}`;

interface SyncRenderOutput {
export interface SyncRenderOutput {
/** HTML that goes into the `<head>` */
head: string;
/** @deprecated use `body` instead */
Expand All @@ -2628,7 +2628,7 @@ declare module 'svelte/server' {
};
}

type RenderOutput = SyncRenderOutput & PromiseLike<SyncRenderOutput>;
export type RenderOutput = SyncRenderOutput & PromiseLike<SyncRenderOutput>;

export {};
}
Expand Down