Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSC: Remove redundant code in register.ts #10743

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 8 additions & 23 deletions packages/vite/src/middleware/register.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -21,13 +21,13 @@ type GroupedMw = Record<string, Middleware[]>
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]',
)
}
}
Expand Down Expand Up @@ -104,28 +104,13 @@ export const createMiddlewareRouter = async (
vite?: ViteDevServer,
): Promise<Router.Instance<any>> => {
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()
Expand Down
Loading