Skip to main content

svelte/legacy

This module provides various functions for use during the migration, since some features can’t be replaced one to one with new features. All imports are marked as deprecated and should be migrated away from over time.

import {
	function asClassComponent<Props extends Record<string, any>, Exports extends Record<string, any>, Events extends Record<string, any>, Slots extends Record<string, any>>(component: SvelteComponent<Props, Events, Slots> | Component<Props>): ComponentType<SvelteComponent<Props, Events, Slots> & Exports>

Takes the component function and returns a Svelte 4 compatible component constructor.

@deprecatedUse this only as a temporary solution to migrate your imperative component code to Svelte 5.
asClassComponent
,
function createBubbler(): (type: string) => (event: Event) => boolean

Function to create a bubble function that mimic the behavior of on:click without handler available in svelte 4.

@deprecatedUse this only as a temporary solution to migrate your automatically delegated events in Svelte 5.
createBubbler
,
function createClassComponent<Props extends Record<string, any>, Exports extends Record<string, any>, Events extends Record<string, any>, Slots extends Record<string, any>>(options: ComponentConstructorOptions<Props> & {
    component: ComponentType<SvelteComponent<Props, Events, Slots>> | Component<Props>;
}): SvelteComponent<Props, Events, Slots> & Exports

Takes the same options as a Svelte 4 component and the component function and returns a Svelte 4 compatible component.

@deprecatedUse this only as a temporary solution to migrate your imperative component code to Svelte 5.
createClassComponent
,
function handlers(...handlers: EventListener[]): EventListener

Function to mimic the multiple listeners available in svelte 4

@deprecated
handlers, function nonpassive(node: HTMLElement, [event, handler]: [event: string, handler: () => EventListener]): void

Substitute for the nonpassive event modifier, implemented as an action

@deprecated
nonpassive
,
function once(fn: (event: Event, ...args: Array<unknown>) => void): (event: Event, ...args: unknown[]) => void

Substitute for the once event modifier

@deprecated
once
,
function passive(node: HTMLElement, [event, handler]: [event: string, handler: () => EventListener]): void

Substitute for the passive event modifier, implemented as an action

@deprecated
passive
,
function preventDefault(fn: (event: Event, ...args: Array<unknown>) => void): (event: Event, ...args: unknown[]) => void

Substitute for the preventDefault event modifier

@deprecated
preventDefault
,
function run(fn: () => void | (() => void)): void

Runs the given function once immediately on the server, and works like $effect.pre on the client.

@deprecatedUse this only as a temporary solution to migrate your component code to Svelte 5.
run
,
function self(fn: (event: Event, ...args: Array<unknown>) => void): (event: Event, ...args: unknown[]) => void

Substitute for the self event modifier

@deprecated
self
,
function stopImmediatePropagation(fn: (event: Event, ...args: Array<unknown>) => void): (event: Event, ...args: unknown[]) => void

Substitute for the stopImmediatePropagation event modifier

@deprecated
stopImmediatePropagation
,
function stopPropagation(fn: (event: Event, ...args: Array<unknown>) => void): (event: Event, ...args: unknown[]) => void

Substitute for the stopPropagation event modifier

@deprecated
stopPropagation
,
function trusted(fn: (event: Event, ...args: Array<unknown>) => void): (event: Event, ...args: unknown[]) => void

Substitute for the trusted event modifier

@deprecated
trusted
} from 'svelte/legacy';

asClassComponent

Use this only as a temporary solution to migrate your imperative component code to Svelte 5.

Takes the component function and returns a Svelte 4 compatible component constructor.

function asClassComponent<
	Props extends Record<string, any>,
	Exports extends Record<string, any>,
	Events extends Record<string, any>,
	Slots extends Record<string, any>
>(
	component:
		| SvelteComponent<Props, Events, Slots>
		| Component<Props>
): ComponentType<
	SvelteComponent<Props, Events, Slots> & Exports
>;

createBubbler

Use this only as a temporary solution to migrate your automatically delegated events in Svelte 5.

Function to create a bubble function that mimic the behavior of on:click without handler available in svelte 4.

function createBubbler(): (
	type: string
) => (event: Event) => boolean;

createClassComponent

Use this only as a temporary solution to migrate your imperative component code to Svelte 5.

Takes the same options as a Svelte 4 component and the component function and returns a Svelte 4 compatible component.

function createClassComponent<
	Props extends Record<string, any>,
	Exports extends Record<string, any>,
	Events extends Record<string, any>,
	Slots extends Record<string, any>
>(
	options: ComponentConstructorOptions<Props> & {
		component:
			| ComponentType<SvelteComponent<Props, Events, Slots>>
			| Component<Props>;
	}
): SvelteComponent<Props, Events, Slots> & Exports;

handlers

Function to mimic the multiple listeners available in svelte 4

function handlers(
	...handlers: EventListener[]
): EventListener;

nonpassive

Substitute for the nonpassive event modifier, implemented as an action

function nonpassive(
	node: HTMLElement,
	[event, handler]: [
		event: string,
		handler: () => EventListener
	]
): void;

once

Substitute for the once event modifier

function once(
	fn: (event: Event, ...args: Array<unknown>) => void
): (event: Event, ...args: unknown[]) => void;

passive

Substitute for the passive event modifier, implemented as an action

function passive(
	node: HTMLElement,
	[event, handler]: [
		event: string,
		handler: () => EventListener
	]
): void;

preventDefault

Substitute for the preventDefault event modifier

function preventDefault(
	fn: (event: Event, ...args: Array<unknown>) => void
): (event: Event, ...args: unknown[]) => void;

run

Use this only as a temporary solution to migrate your component code to Svelte 5.

Runs the given function once immediately on the server, and works like $effect.pre on the client.

function run(fn: () => void | (() => void)): void;

self

Substitute for the self event modifier

function self(
	fn: (event: Event, ...args: Array<unknown>) => void
): (event: Event, ...args: unknown[]) => void;

stopImmediatePropagation

Substitute for the stopImmediatePropagation event modifier

function stopImmediatePropagation(
	fn: (event: Event, ...args: Array<unknown>) => void
): (event: Event, ...args: unknown[]) => void;

stopPropagation

Substitute for the stopPropagation event modifier

function stopPropagation(
	fn: (event: Event, ...args: Array<unknown>) => void
): (event: Event, ...args: unknown[]) => void;

trusted

Substitute for the trusted event modifier

function trusted(
	fn: (event: Event, ...args: Array<unknown>) => void
): (event: Event, ...args: unknown[]) => void;

Edit this page on GitHub