Skip to content

Commit

Permalink
fix: allow client only middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
tannerlinsley committed Jan 25, 2025
1 parent b9f44bc commit 3514996
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions packages/start-plugin/src/compilers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,17 +413,16 @@ function handleCreateMiddlewareCallExpression(
}
}

const useFnPath = callExpressionPaths.server?.get(
const serverFnPath = callExpressionPaths.server?.get(
'arguments.0',
) as babel.NodePath<any>

if (!callExpressionPaths.server || !useFnPath.node) {
throw new Error('createMiddleware must be called with a "use" property!')
}

// If we're on the client, remove the server call expression

if (opts.env === 'client' || opts.env === 'ssr') {
if (
callExpressionPaths.server &&
serverFnPath.node &&
(opts.env === 'client' || opts.env === 'ssr')
) {
// If we're on the client, remove the server call expression
if (t.isMemberExpression(callExpressionPaths.server.node.callee)) {
callExpressionPaths.server.replaceWith(
callExpressionPaths.server.node.callee.object,
Expand Down

0 comments on commit 3514996

Please sign in to comment.