legacy-server.js — svelte Source File
Architecture documentation for legacy-server.js, a javascript file in the svelte codebase. 6 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR b5fce8f9_a98c_49f9_4b3b_91a4e206908c["legacy-server.js"] 9478150a_17fe_efce_10bd_3938ed8558e2["legacy-client.js"] b5fce8f9_a98c_49f9_4b3b_91a4e206908c --> 9478150a_17fe_efce_10bd_3938ed8558e2 75ae9027_9abc_8e62_0404_f3531b219452["asClassComponent"] b5fce8f9_a98c_49f9_4b3b_91a4e206908c --> 75ae9027_9abc_8e62_0404_f3531b219452 6b2154e5_6ad8_6202_e830_6eed90af75e8["createClassComponent"] b5fce8f9_a98c_49f9_4b3b_91a4e206908c --> 6b2154e5_6ad8_6202_e830_6eed90af75e8 1c4bc493_24af_177e_7307_a999997aceac["index.js"] b5fce8f9_a98c_49f9_4b3b_91a4e206908c --> 1c4bc493_24af_177e_7307_a999997aceac 91da79a6_48be_3e67_5beb_aa47cf753c81["render"] b5fce8f9_a98c_49f9_4b3b_91a4e206908c --> 91da79a6_48be_3e67_5beb_aa47cf753c81 3c211218_0172_f6af_dd4f_da8028a531fc["index.js"] b5fce8f9_a98c_49f9_4b3b_91a4e206908c --> 3c211218_0172_f6af_dd4f_da8028a531fc style b5fce8f9_a98c_49f9_4b3b_91a4e206908c fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/** @import { SvelteComponent } from '../index.js' */
/** @import { Csp } from '#server' */
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';
// By having this as a separate entry point for server environments, we save the client bundle from having to include the server runtime
export { createClassComponent };
/** @typedef {{ head: string, html: string, css: { code: string, map: null }; hashes?: { script: `sha256-${string}`[] } }} LegacyRenderResult */
/**
* Takes a Svelte 5 component and returns a Svelte 4 compatible component constructor.
*
* @deprecated Use this only as a temporary solution to migrate your imperative component code to Svelte 5.
*
* @template {Record<string, any>} Props
* @template {Record<string, any>} Exports
* @template {Record<string, any>} Events
* @template {Record<string, any>} Slots
*
* @param {SvelteComponent<Props, Events, Slots>} component
* @returns {typeof SvelteComponent<Props, Events, Slots> & Exports}
*/
export function asClassComponent(component) {
const component_constructor = as_class_component(component);
/** @type {(props?: {}, opts?: { $$slots?: {}; context?: Map<any, any>; csp?: Csp }) => LegacyRenderResult & PromiseLike<LegacyRenderResult> } */
const _render = (props, { context, csp } = {}) => {
// @ts-expect-error the typings are off, but this will work if the component is compiled in SSR mode
const result = render(component, { props, context, csp });
const munged = Object.defineProperties(
/** @type {LegacyRenderResult & PromiseLike<LegacyRenderResult>} */ ({}),
{
css: {
value: { code: '', map: null }
},
head: {
get: () => result.head
},
html: {
get: () => result.body
},
then: {
/**
* this is not type-safe, but honestly it's the best I can do right now, and it's a straightforward function.
*
* @template TResult1
* @template [TResult2=never]
* @param { (value: LegacyRenderResult) => TResult1 } onfulfilled
* @param { (reason: unknown) => TResult2 } onrejected
*/
value: (onfulfilled, onrejected) => {
if (!async_mode_flag) {
const user_result = onfulfilled({
css: munged.css,
head: munged.head,
html: munged.html
});
return Promise.resolve(user_result);
}
return result.then((result) => {
return onfulfilled({
css: munged.css,
head: result.head,
html: result.body,
hashes: result.hashes
});
}, onrejected);
}
}
}
);
return munged;
};
// @ts-expect-error this is present for SSR
component_constructor.render = _render;
// @ts-ignore
return component_constructor;
}
/**
* Runs the given function once immediately on the server, and works like `$effect.pre` on the client.
*
* @deprecated Use this only as a temporary solution to migrate your component code to Svelte 5.
* @param {() => void | (() => void)} fn
* @returns {void}
*/
export function run(fn) {
fn();
}
const noop = () => {};
// event stuff, no need to worry about it for SSR but needs to be there or it will crash
export {
noop as handlers,
noop as createBubbler,
noop as once,
noop as preventDefault,
noop as self,
noop as stopImmediatePropagation,
noop as stopPropagation,
noop as trusted,
noop as passive,
noop as nonpassive
};
Domain
Subdomains
Functions
Source
Frequently Asked Questions
What does legacy-server.js do?
legacy-server.js is a source file in the svelte codebase, written in javascript. It belongs to the SharedInternal domain, BitFlags subdomain.
What functions are defined in legacy-server.js?
legacy-server.js defines 3 function(s): asClassComponent, noop, run.
What does legacy-server.js depend on?
legacy-server.js imports 6 module(s): asClassComponent, createClassComponent, index.js, index.js, legacy-client.js, render.
Where is legacy-server.js in the architecture?
legacy-server.js is located at packages/svelte/src/legacy/legacy-server.js (domain: SharedInternal, subdomain: BitFlags, directory: packages/svelte/src/legacy).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free