From 2c25d50e79113aad6db7eb39d8dd128ec2a0cc27 Mon Sep 17 00:00:00 2001 From: Marcel Kloubert Date: Mon, 14 Aug 2023 07:52:50 +0200 Subject: [PATCH] fix createWithServerProps() --- CHANGELOG.md | 2 +- package-lock.json | 4 ++-- package.json | 4 ++-- src/middlewares/withServerProps.ts | 17 ++++++----------- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6362e8..fc25828 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log (@egomobile/next-utils) -## 0.9.3 +## 0.9.4 - **BREAKING CHANGE**: improve use of execution contextes of `EnhanceApiContext` diff --git a/package-lock.json b/package-lock.json index ff27535..6aef68f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@egomobile/next-utils", - "version": "0.9.3", + "version": "0.9.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@egomobile/next-utils", - "version": "0.9.3", + "version": "0.9.4", "license": "LGPL-3.0", "dependencies": { "@egomobile/api-utils": "^1.2.0", diff --git a/package.json b/package.json index 83dee89..3b98baf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@egomobile/next-utils", - "version": "0.9.3", + "version": "0.9.4", "description": "Handy utils and extensions for Next.js", "main": "lib/index.js", "engines": { @@ -75,4 +75,4 @@ "@egomobile/http-server": ">=0.63.1", "next": ">=13.0.0" } -} +} \ No newline at end of file diff --git a/src/middlewares/withServerProps.ts b/src/middlewares/withServerProps.ts index 21f839b..d990a81 100644 --- a/src/middlewares/withServerProps.ts +++ b/src/middlewares/withServerProps.ts @@ -131,16 +131,6 @@ export function createWithServerProps( null; return (action?, options?) => { - if (!action) { - return wrapServerHandler(async () => { - return { - "props": {} - }; - }, { - "use": options?.use - }); - } - return wrapServerHandler(async (context) => { try { const actionContext: IWithServerPropsActionContext = { @@ -167,7 +157,12 @@ export function createWithServerProps( }; } - const resultProps = await action(enhanceExecCtx.context as unknown as TContext); + let resultProps = await action?.(enhanceExecCtx.context as unknown as TContext); + if (!resultProps) { + resultProps = { + "props": {} + }; + } return cloneObj( deepmerge(