From 14330bd770aebb1ad79fa88647440de76349dfd4 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 24 Feb 2025 16:55:07 -0500 Subject: [PATCH] add Promise.withResolvers shim for convenience --- playgrounds/sandbox/ssr-common.js | 11 +++++++++++ playgrounds/sandbox/ssr-dev.js | 1 + playgrounds/sandbox/ssr-prod.js | 1 + 3 files changed, 13 insertions(+) create mode 100644 playgrounds/sandbox/ssr-common.js diff --git a/playgrounds/sandbox/ssr-common.js b/playgrounds/sandbox/ssr-common.js new file mode 100644 index 0000000000..60c6b52eb1 --- /dev/null +++ b/playgrounds/sandbox/ssr-common.js @@ -0,0 +1,11 @@ +Promise.withResolvers ??= () => { + let resolve; + let reject; + + const promise = new Promise((f, r) => { + resolve = f; + reject = r; + }); + + return { promise, resolve, reject }; +}; diff --git a/playgrounds/sandbox/ssr-dev.js b/playgrounds/sandbox/ssr-dev.js index 01ce14e266..e019b234a6 100644 --- a/playgrounds/sandbox/ssr-dev.js +++ b/playgrounds/sandbox/ssr-dev.js @@ -5,6 +5,7 @@ import { fileURLToPath } from 'node:url'; import polka from 'polka'; import { createServer as createViteServer } from 'vite'; import { render } from 'svelte/server'; +import './ssr-common.js'; const PORT = process.env.PORT || '5173'; diff --git a/playgrounds/sandbox/ssr-prod.js b/playgrounds/sandbox/ssr-prod.js index 1ed9435249..e8f74ee93a 100644 --- a/playgrounds/sandbox/ssr-prod.js +++ b/playgrounds/sandbox/ssr-prod.js @@ -3,6 +3,7 @@ import path from 'node:path'; import polka from 'polka'; import { render } from 'svelte/server'; import App from './src/App.svelte'; +import './ssr-common.js'; const { head, body } = render(App);