react-streaming
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -11,3 +11,3 @@ export { useSuspense }; | ||
state: 'pending'; | ||
promise: Promise<unknown>; | ||
promise: Promise<void>; | ||
} | { | ||
@@ -14,0 +14,0 @@ state: 'error'; |
@@ -68,7 +68,7 @@ "use strict"; | ||
if (!suspense) { | ||
let promise; | ||
let ret; | ||
try { | ||
promise = resolver(); | ||
ret = resolver(); | ||
DEBUG && console.log('resolver()'); | ||
if (!(0, utils_1.isPromise)(promise)) { | ||
if (!(0, utils_1.isPromise)(ret)) { | ||
const fnName = asyncFnName || 'fn'; | ||
@@ -79,6 +79,6 @@ (0, utils_1.assertWarning)(false, `[useAsync(key, ${fnName})] You provided a function \`${fnName}\` which didn't return a promise`, { | ||
}); | ||
suspense = suspenses[suspenseId] = { state: 'done', value: promise }; | ||
suspense = suspenses[suspenseId] = { state: 'done', value: ret }; | ||
} | ||
else { | ||
promise.then((value) => { | ||
const promise = ret.then((value) => { | ||
updateSuspenseAsync({ state: 'done', value }); | ||
@@ -97,2 +97,4 @@ DEBUG && console.log('=== resolver() done', suspense); | ||
if (suspense.state === 'pending') { | ||
bugCatcher(); | ||
(0, utils_1.assert)((0, utils_1.isPromise)(suspense.promise)); | ||
throw suspense.promise; | ||
@@ -114,2 +116,16 @@ } | ||
exports.useSuspense = useSuspense; | ||
// Infinite look catcher. | ||
// - It works like this: throw an error if `bugCatcher()` is called >1000 times within 30 seconds. | ||
var count; | ||
function bugCatcher() { | ||
if (count === undefined) { | ||
count = 0; | ||
setTimeout(() => { | ||
count = undefined; | ||
}, 30 * 1000); | ||
} | ||
if (++count > 1000) { | ||
throw new Error('Infinite loop detected. This possibly is a React bug. Reach out to the https://github.com/brillout/react-streaming maintainer.'); | ||
} | ||
} | ||
function getSuspenseId(key, elementId) { | ||
@@ -116,0 +132,0 @@ (0, utils_1.assert)(!elementId.includes('_')); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.projectInfo = void 0; | ||
const PROJECT_VERSION = '0.3.1'; | ||
const PROJECT_VERSION = '0.3.2'; | ||
exports.projectInfo = { | ||
@@ -6,0 +6,0 @@ projectName: 'react-streaming', |
@@ -11,3 +11,3 @@ export { useSuspense }; | ||
state: 'pending'; | ||
promise: Promise<unknown>; | ||
promise: Promise<void>; | ||
} | { | ||
@@ -14,0 +14,0 @@ state: 'error'; |
@@ -66,7 +66,7 @@ export { useSuspense }; | ||
if (!suspense) { | ||
let promise; | ||
let ret; | ||
try { | ||
promise = resolver(); | ||
ret = resolver(); | ||
DEBUG && console.log('resolver()'); | ||
if (!isPromise(promise)) { | ||
if (!isPromise(ret)) { | ||
const fnName = asyncFnName || 'fn'; | ||
@@ -77,6 +77,6 @@ assertWarning(false, `[useAsync(key, ${fnName})] You provided a function \`${fnName}\` which didn't return a promise`, { | ||
}); | ||
suspense = suspenses[suspenseId] = { state: 'done', value: promise }; | ||
suspense = suspenses[suspenseId] = { state: 'done', value: ret }; | ||
} | ||
else { | ||
promise.then((value) => { | ||
const promise = ret.then((value) => { | ||
updateSuspenseAsync({ state: 'done', value }); | ||
@@ -95,2 +95,4 @@ DEBUG && console.log('=== resolver() done', suspense); | ||
if (suspense.state === 'pending') { | ||
bugCatcher(); | ||
assert(isPromise(suspense.promise)); | ||
throw suspense.promise; | ||
@@ -111,2 +113,16 @@ } | ||
} | ||
// Infinite look catcher. | ||
// - It works like this: throw an error if `bugCatcher()` is called >1000 times within 30 seconds. | ||
var count; | ||
function bugCatcher() { | ||
if (count === undefined) { | ||
count = 0; | ||
setTimeout(() => { | ||
count = undefined; | ||
}, 30 * 1000); | ||
} | ||
if (++count > 1000) { | ||
throw new Error('Infinite loop detected. This possibly is a React bug. Reach out to the https://github.com/brillout/react-streaming maintainer.'); | ||
} | ||
} | ||
function getSuspenseId(key, elementId) { | ||
@@ -113,0 +129,0 @@ assert(!elementId.includes('_')); |
@@ -1,2 +0,2 @@ | ||
const PROJECT_VERSION = '0.3.1'; | ||
const PROJECT_VERSION = '0.3.2'; | ||
export const projectInfo = { | ||
@@ -3,0 +3,0 @@ projectName: 'react-streaming', |
{ | ||
"name": "react-streaming", | ||
"description": "React 18 Streaming. Full-fledged & Easy.", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"main": "./dist/cjs/server/hooks.js", | ||
@@ -6,0 +6,0 @@ "peerDependencies": { |
81692
1680