From db305a07f25ad7370e7ee96f5d3d73ba575ea712 Mon Sep 17 00:00:00 2001 From: Paolo Ricciuti Date: Mon, 7 Oct 2024 21:46:07 +0200 Subject: [PATCH] fix: allow imports from `svelte/legacy` in SSR (#13523) Apps could crash if they import it in a way that is not treeshaken --- .changeset/two-chefs-lie.md | 5 ++ packages/svelte/src/legacy/legacy-server.js | 16 ++++ .../samples/legacy-imports/Button.svelte | 0 .../samples/legacy-imports/_expected.html | 1 + .../samples/legacy-imports/main.svelte | 82 +++++++++++++++++++ 5 files changed, 104 insertions(+) create mode 100644 .changeset/two-chefs-lie.md create mode 100644 packages/svelte/tests/server-side-rendering/samples/legacy-imports/Button.svelte create mode 100644 packages/svelte/tests/server-side-rendering/samples/legacy-imports/_expected.html create mode 100644 packages/svelte/tests/server-side-rendering/samples/legacy-imports/main.svelte diff --git a/.changeset/two-chefs-lie.md b/.changeset/two-chefs-lie.md new file mode 100644 index 0000000000..cc4be41843 --- /dev/null +++ b/.changeset/two-chefs-lie.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: allow imports from `svelte/legacy` in SSR diff --git a/packages/svelte/src/legacy/legacy-server.js b/packages/svelte/src/legacy/legacy-server.js index 35acc61526..60bd8c9fc6 100644 --- a/packages/svelte/src/legacy/legacy-server.js +++ b/packages/svelte/src/legacy/legacy-server.js @@ -48,3 +48,19 @@ export function asClassComponent(component) { 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 +}; diff --git a/packages/svelte/tests/server-side-rendering/samples/legacy-imports/Button.svelte b/packages/svelte/tests/server-side-rendering/samples/legacy-imports/Button.svelte new file mode 100644 index 0000000000..e69de29bb2 diff --git a/packages/svelte/tests/server-side-rendering/samples/legacy-imports/_expected.html b/packages/svelte/tests/server-side-rendering/samples/legacy-imports/_expected.html new file mode 100644 index 0000000000..b9727af449 --- /dev/null +++ b/packages/svelte/tests/server-side-rendering/samples/legacy-imports/_expected.html @@ -0,0 +1 @@ +
\ No newline at end of file diff --git a/packages/svelte/tests/server-side-rendering/samples/legacy-imports/main.svelte b/packages/svelte/tests/server-side-rendering/samples/legacy-imports/main.svelte new file mode 100644 index 0000000000..b6cd7566ca --- /dev/null +++ b/packages/svelte/tests/server-side-rendering/samples/legacy-imports/main.svelte @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
\ No newline at end of file