From 1e476a45c77ef92f02576e2d11829d3510a2d757 Mon Sep 17 00:00:00 2001 From: Tobbe Lundberg Date: Thu, 6 Jun 2024 13:37:40 +0200 Subject: [PATCH] RSC: Remove redundant code in register.ts --- packages/vite/src/middleware/register.ts | 31 ++++++------------------ 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/packages/vite/src/middleware/register.ts b/packages/vite/src/middleware/register.ts index 94cb2e2d756e..0381eb3ddd85 100644 --- a/packages/vite/src/middleware/register.ts +++ b/packages/vite/src/middleware/register.ts @@ -2,7 +2,7 @@ import fmw from 'find-my-way' import type Router from 'find-my-way' import type { ViteDevServer } from 'vite' -import { getConfig, getPaths } from '@redwoodjs/project-config' +import { getPaths } from '@redwoodjs/project-config' import type { EntryServer } from '../types' import { makeFilePath, ssrLoadEntryServer } from '../utils' @@ -21,13 +21,13 @@ type GroupedMw = Record const validateMw = (mw: MiddlewareClass | Middleware): Middleware => { if (typeof mw === 'function') { return mw - } - if (typeof mw === 'object' && typeof mw.invoke === 'function') { + } else if (typeof mw === 'object' && typeof mw.invoke === 'function') { return mw.invoke.bind(mw) } else { console.error('Received as middleware: ', mw) throw new Error( - 'Please check the return on registerMiddleware. Must be a Middleware function, Class or tuple of [Middleware, string]', + 'Please check the return on registerMiddleware. Must be a Middleware ' + + 'function, Class or tuple of [Middleware, string]', ) } } @@ -104,28 +104,13 @@ export const createMiddlewareRouter = async ( vite?: ViteDevServer, ): Promise> => { const rwPaths = getPaths() - const rwConfig = getConfig() - const rscEnabled = rwConfig.experimental?.rsc?.enabled - - let entryServerImport: EntryServer - - if (vite) { - entryServerImport = await ssrLoadEntryServer(vite) - } else { - // This imports from dist! - if (rscEnabled) { - entryServerImport = await import( - makeFilePath(rwPaths.web.distSsrEntryServer) - ) - } else { - entryServerImport = await import( - makeFilePath(rwPaths.web.distSsrEntryServer) - ) - } - } + const entryServerImport: EntryServer = vite + ? await ssrLoadEntryServer(vite) + : await import(makeFilePath(rwPaths.web.distSsrEntryServer)) const { registerMiddleware } = entryServerImport + if (!registerMiddleware) { // Empty router return fmw()