diff --git a/.changeset/olive-mugs-search.md b/.changeset/olive-mugs-search.md new file mode 100644 index 000000000000..86613bcb3549 --- /dev/null +++ b/.changeset/olive-mugs-search.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +chore: remove internal class-replacement hack that isn't needed anymore diff --git a/packages/kit/src/exports/vite/dev/index.js b/packages/kit/src/exports/vite/dev/index.js index 7049d8910508..ded4685f527c 100644 --- a/packages/kit/src/exports/vite/dev/index.js +++ b/packages/kit/src/exports/vite/dev/index.js @@ -392,32 +392,6 @@ export async function dev(vite, vite_config, svelte_config) { } }); - async function align_exports() { - // This shameful hack allows us to load runtime server code via Vite - // while apps load `HttpError` and `Redirect` in Node, without - // causing `instanceof` checks to fail - const control_module_node = await import('../../../runtime/control.js'); - const control_module_vite = await vite.ssrLoadModule(`${runtime_base}/control.js`); - - control_module_node.replace_implementations({ - ActionFailure: control_module_vite.ActionFailure, - HttpError: control_module_vite.HttpError, - Redirect: control_module_vite.Redirect, - SvelteKitError: control_module_vite.SvelteKitError - }); - } - await align_exports(); - const ws_send = vite.ws.send; - /** @param {any} args */ - vite.ws.send = function (...args) { - // We need to reapply the patch after Vite did dependency optimizations - // because that clears the module resolutions - if (args[0]?.type === 'full-reload' && args[0].path === '*') { - void align_exports(); - } - return ws_send.apply(vite.ws, args); - }; - vite.middlewares.use((req, res, next) => { const base = `${vite.config.server.https ? 'https' : 'http'}://${ req.headers[':authority'] || req.headers.host diff --git a/packages/kit/src/runtime/control.js b/packages/kit/src/runtime/control.js index 64737a9cff1d..aa0b93f8965b 100644 --- a/packages/kit/src/runtime/control.js +++ b/packages/kit/src/runtime/control.js @@ -61,27 +61,3 @@ export class ActionFailure { this.data = data; } } - -/** - * This is a grotesque hack that, in dev, allows us to replace the implementations - * of these classes that you'd get by importing them from `@sveltejs/kit` with the - * ones that are imported via Vite and loaded internally, so that instanceof - * checks work even though SvelteKit imports this module via Vite and consumers - * import it via Node - * @param {{ - * ActionFailure: typeof ActionFailure; - * HttpError: typeof HttpError; - * Redirect: typeof Redirect; - * SvelteKitError: typeof SvelteKitError; - * }} implementations - */ -export function replace_implementations(implementations) { - // @ts-expect-error - ActionFailure = implementations.ActionFailure; // eslint-disable-line no-class-assign - // @ts-expect-error - HttpError = implementations.HttpError; // eslint-disable-line no-class-assign - // @ts-expect-error - Redirect = implementations.Redirect; // eslint-disable-line no-class-assign - // @ts-expect-error - SvelteKitError = implementations.SvelteKitError; // eslint-disable-line no-class-assign -}