feat: export RenderOutput, SyncRenderOutput, Csp and Sha256Source from svelte/server (#18648)

`render` returns `RenderOutput` and takes `csp: Csp`, but both are
declared in `src/internal/server/types.d.ts` and never exported. The
generated `svelte/server` block has them without `export`, so nothing
outside the repo can import them and the docs page names `RenderOutput`
as the return type with nothing on the page defining it.

Moves them into `src/server/public.d.ts` the way `svelte/motion` went in
#17967, rather than re-exporting internals.
pull/18680/merge
Nic Polumeyv 4 days ago committed by GitHub
parent faf1e103c5
commit cac27c783e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': minor
---
feat: export `RenderOutput`, `SyncRenderOutput`, `Csp` and `Sha256Source` from `svelte/server`

@ -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';

@ -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';

@ -15,8 +15,6 @@ export interface SSRContext {
element?: Element;
}
export type Csp = { nonce?: string; hash?: boolean };
export interface HydratableLookupEntry {
value: unknown;
serialized: string;
@ -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>;

@ -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';

@ -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.

@ -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>;

@ -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')[];

@ -2616,11 +2616,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 */
@ -2632,7 +2632,7 @@ declare module 'svelte/server' {
};
}
type RenderOutput = SyncRenderOutput & PromiseLike<SyncRenderOutput>;
export type RenderOutput = SyncRenderOutput & PromiseLike<SyncRenderOutput>;
export {};
}

Loading…
Cancel
Save