Skip to content

Commit 71daa00

Browse files
use isPromise to check if the result is a promise
1 parent 0a2772f commit 71daa00

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

node_package/src/isServerRenderResult.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function isServerRenderHash(testValue: CreateReactOutputResult):
99
(testValue as ServerRenderResult).error);
1010
}
1111

12-
export function isPromise(testValue: CreateReactOutputResult):
13-
testValue is Promise<string> {
14-
return !!((testValue as Promise<string>).then);
12+
export function isPromise<T>(testValue: CreateReactOutputResult | Promise<T> | string):
13+
testValue is Promise<T> {
14+
return !!((testValue as Promise<T>).then);
1515
}

node_package/src/serverRenderReactComponent.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import type { ReactElement } from 'react';
33

44
import ComponentRegistry from './ComponentRegistry';
55
import createReactOutput from './createReactOutput';
6-
import {isServerRenderHash, isPromise} from
7-
'./isServerRenderResult';
6+
import { isServerRenderHash, isPromise } from './isServerRenderResult';
87
import buildConsoleReplay from './buildConsoleReplay';
98
import handleError from './handleError';
109
import type { RenderParams, RenderResult, RenderingError } from './types/index';
@@ -162,12 +161,12 @@ const serverRenderReactComponent: typeof serverRenderReactComponentInternal = (o
162161
} finally {
163162
// Reset console history after each render.
164163
// See `RubyEmbeddedJavaScript.console_polyfill` for initialization.
165-
if (!result || typeof(result) === 'string') {
166-
console.history = [];
167-
} else {
164+
if (result && isPromise(result)) {
168165
result.finally(() => {
169166
console.history = [];
170167
});
168+
} else {
169+
console.history = [];
171170
}
172171
}
173172
return result;

0 commit comments

Comments
 (0)