react-ssr-prepass
Advanced tools
Comparing version 1.2.1 to 1.3.0-rc.0
"use strict"; | ||
function _interopDefault(ex) { | ||
return ex && "object" == typeof ex && "default" in ex ? ex.default : ex; | ||
} | ||
var React = require("react"); | ||
var React__default = _interopDefault(React); | ||
function _interopDefaultLegacy(e) { | ||
return e && "object" == typeof e && "default" in e ? e : { | ||
default: e | ||
}; | ||
} | ||
var is = require("react-is"); | ||
var React__default = _interopDefaultLegacy(React); | ||
var is$1 = _interopDefault(require("object-is")); | ||
function _extends() { | ||
@@ -29,26 +27,66 @@ return (_extends = Object.assign || function(target) { | ||
var REACT_ELEMENT_TYPE = is.Element; | ||
var Element = 60103; | ||
var REACT_PORTAL_TYPE = is.Portal; | ||
var Portal = 60106; | ||
var REACT_FRAGMENT_TYPE = is.Fragment; | ||
var Fragment = 60107; | ||
var REACT_STRICT_MODE_TYPE = is.StrictMode; | ||
var StrictMode = 60108; | ||
var REACT_PROFILER_TYPE = is.Profiler; | ||
var Profiler = 60114; | ||
var REACT_PROVIDER_TYPE = is.ContextProvider; | ||
var ContextProvider = 60109; | ||
var REACT_CONTEXT_TYPE = is.ContextConsumer; | ||
var ContextConsumer = 60110; | ||
var REACT_CONCURRENT_MODE_TYPE = is.ConcurrentMode; | ||
var ConcurrentMode = 60111; | ||
var REACT_FORWARD_REF_TYPE = is.ForwardRef; | ||
var ForwardRef = 60112; | ||
var REACT_SUSPENSE_TYPE = is.Suspense; | ||
var Suspense = 60113; | ||
var REACT_MEMO_TYPE = is.Memo; | ||
var Memo = 60115; | ||
var REACT_LAZY_TYPE = is.Lazy; | ||
var Lazy = 60116; | ||
if ("function" == typeof Symbol && Symbol.for) { | ||
var symbolFor = Symbol.for; | ||
Element = symbolFor("react.element"); | ||
Portal = symbolFor("react.portal"); | ||
Fragment = symbolFor("react.fragment"); | ||
StrictMode = symbolFor("react.strict_mode"); | ||
Profiler = symbolFor("react.profiler"); | ||
ContextProvider = symbolFor("react.provider"); | ||
ContextConsumer = symbolFor("react.context"); | ||
ConcurrentMode = Symbol.for("react.concurrent_mode"); | ||
ForwardRef = symbolFor("react.forward_ref"); | ||
Suspense = symbolFor("react.suspense"); | ||
Memo = symbolFor("react.memo"); | ||
Lazy = symbolFor("react.lazy"); | ||
} | ||
var REACT_ELEMENT_TYPE = Element; | ||
var REACT_PORTAL_TYPE = Portal; | ||
var REACT_FRAGMENT_TYPE = Fragment; | ||
var REACT_STRICT_MODE_TYPE = StrictMode; | ||
var REACT_PROFILER_TYPE = Profiler; | ||
var REACT_PROVIDER_TYPE = ContextProvider; | ||
var REACT_CONTEXT_TYPE = ContextConsumer; | ||
var REACT_CONCURRENT_MODE_TYPE = ConcurrentMode; | ||
var REACT_FORWARD_REF_TYPE = ForwardRef; | ||
var REACT_SUSPENSE_TYPE = Suspense; | ||
var REACT_MEMO_TYPE = Memo; | ||
var REACT_LAZY_TYPE = Lazy; | ||
var toArray = React.Children.toArray; | ||
@@ -143,2 +181,16 @@ | ||
var currentErrorFrame = null; | ||
var getCurrentErrorFrame = function() { | ||
return currentErrorFrame; | ||
}; | ||
var setCurrentErrorFrame = function(frame) { | ||
currentErrorFrame = frame || null; | ||
}; | ||
var objectIs = "function" == typeof Object.is ? Object.is : function is(x, y) { | ||
return x === y && (0 !== x || 1 / x == 1 / y) || x != x && y != y; | ||
}; | ||
var currentIdentity = null; | ||
@@ -239,3 +291,3 @@ | ||
for (var i = 0; i < prevDeps.length && i < nextDeps.length; i++) { | ||
if (!is$1(nextDeps[i], prevDeps[i])) { | ||
if (!objectIs(nextDeps[i], prevDeps[i])) { | ||
return !1; | ||
@@ -327,15 +379,25 @@ } | ||
var resolve = function(type) { | ||
type._status = 0; | ||
return type._ctor().then((function(Component) { | ||
var payload = type._payload || type; | ||
if (0 === payload._status) { | ||
return payload._result; | ||
} else if (1 === payload._status) { | ||
return Promise.resolve(payload._result); | ||
} else if (2 === payload._status) { | ||
return Promise.reject(payload._result); | ||
} | ||
payload._status = 0; | ||
return payload._result = (payload._ctor || payload._result)().then((function(Component) { | ||
payload._result = Component; | ||
if ("function" == typeof Component) { | ||
type._result = Component; | ||
type._status = 1; | ||
payload._status = 1; | ||
} else if (null !== Component && "object" == typeof Component && "function" == typeof Component.default) { | ||
type._result = Component.default; | ||
type._status = 1; | ||
payload._result = Component.default; | ||
payload._status = 1; | ||
} else { | ||
type._status = 2; | ||
payload._status = 2; | ||
} | ||
})).catch((function() { | ||
type._status = 2; | ||
})).catch((function(error) { | ||
payload._status = 2; | ||
payload._result = error; | ||
return Promise.reject(error); | ||
})); | ||
@@ -345,4 +407,5 @@ }; | ||
var render = function(type, props, queue) { | ||
if (1 === type._status) { | ||
return React.createElement(type._result, props); | ||
var payload = type._payload || type; | ||
if (1 === payload._status) { | ||
return React.createElement(payload._result, props); | ||
} | ||
@@ -359,2 +422,3 @@ return null; | ||
kind: "frame.hooks", | ||
errorFrame: getCurrentErrorFrame(), | ||
thenable: thenable, | ||
@@ -401,2 +465,3 @@ props: props, | ||
var updater = { | ||
_thrown: 0, | ||
queue: queue = [], | ||
@@ -428,2 +493,7 @@ isMounted: _ref$1, | ||
} | ||
if ("function" == typeof instance.componentDidCatch || "function" == typeof type.getDerivedStateFromError) { | ||
var frame = makeFrame$1(type, instance, null); | ||
frame.errorFrame = frame; | ||
setCurrentErrorFrame(frame); | ||
} | ||
if ("function" == typeof type.getDerivedStateFromProps) { | ||
@@ -446,4 +516,6 @@ var state = (0, type.getDerivedStateFromProps)(instance.props, instance.state); | ||
contextStore: getCurrentContextStore(), | ||
errorFrame: getCurrentErrorFrame(), | ||
thenable: thenable, | ||
kind: "frame.class", | ||
error: null, | ||
instance: instance, | ||
@@ -501,2 +573,4 @@ type: type | ||
var ReactCurrentDispatcher = React__default.default.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher; | ||
var SHOULD_YIELD = "function" == typeof setImmediate; | ||
@@ -606,7 +680,8 @@ | ||
var child = function(type, props, queue) { | ||
if (2 !== type._status && 1 !== type._status) { | ||
if ((type._payload || type)._status <= 0) { | ||
queue.push({ | ||
kind: "frame.lazy", | ||
contextMap: getCurrentContextMap(), | ||
contextStore: getCurrentContextStore(), | ||
kind: "frame.lazy", | ||
errorFrame: getCurrentErrorFrame(), | ||
thenable: resolve(type), | ||
@@ -647,130 +722,152 @@ props: props, | ||
var visitLoop = function(traversalChildren, traversalMap, traversalStore, queue, visitor) { | ||
var visitLoop = function(traversalChildren, traversalMap, traversalStore, traversalErrorFrame, queue, visitor) { | ||
var prevDispatcher = ReactCurrentDispatcher.current; | ||
var start = Date.now(); | ||
while (traversalChildren.length > 0) { | ||
var element = traversalChildren[traversalChildren.length - 1].shift(); | ||
if (void 0 !== element) { | ||
var children = visitElement(element, queue, visitor); | ||
traversalChildren.push(children); | ||
traversalMap.push(flushPrevContextMap()); | ||
traversalStore.push(flushPrevContextStore()); | ||
} else { | ||
traversalChildren.pop(); | ||
restoreContextMap(traversalMap.pop()); | ||
restoreContextStore(traversalStore.pop()); | ||
try { | ||
ReactCurrentDispatcher.current = Dispatcher; | ||
while (traversalChildren.length > 0) { | ||
var element = traversalChildren[traversalChildren.length - 1].shift(); | ||
if (void 0 !== element) { | ||
var children = visitElement(element, queue, visitor); | ||
traversalChildren.push(children); | ||
traversalMap.push(flushPrevContextMap()); | ||
traversalStore.push(flushPrevContextStore()); | ||
traversalErrorFrame.push(getCurrentErrorFrame()); | ||
} else { | ||
traversalChildren.pop(); | ||
restoreContextMap(traversalMap.pop()); | ||
restoreContextStore(traversalStore.pop()); | ||
setCurrentErrorFrame(traversalErrorFrame.pop()); | ||
} | ||
if (SHOULD_YIELD && Date.now() - start > YIELD_AFTER_MS) { | ||
return !0; | ||
} | ||
} | ||
if (SHOULD_YIELD && Date.now() - start > YIELD_AFTER_MS) { | ||
return !0; | ||
return !1; | ||
} catch (error) { | ||
var errorFrame = getCurrentErrorFrame(); | ||
if (!errorFrame) { | ||
throw error; | ||
} | ||
errorFrame.error = error; | ||
queue.unshift(errorFrame); | ||
return !1; | ||
} finally { | ||
ReactCurrentDispatcher.current = prevDispatcher; | ||
} | ||
return !1; | ||
}; | ||
var makeYieldFrame = function(traversalChildren, traversalMap, traversalStore) { | ||
var makeYieldFrame = function(traversalChildren, traversalMap, traversalStore, traversalErrorFrame) { | ||
return { | ||
contextMap: getCurrentContextMap(), | ||
contextStore: getCurrentContextStore(), | ||
thenable: Promise.resolve(), | ||
errorFrame: getCurrentErrorFrame(), | ||
thenable: null, | ||
kind: "frame.yield", | ||
children: traversalChildren, | ||
map: traversalMap, | ||
store: traversalStore | ||
traversalChildren: traversalChildren, | ||
traversalMap: traversalMap, | ||
traversalStore: traversalStore, | ||
traversalErrorFrame: traversalErrorFrame | ||
}; | ||
}; | ||
var ReactCurrentDispatcher = React__default.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher; | ||
var visit = function(init, queue, visitor) { | ||
var traversalChildren = [ init ]; | ||
var traversalMap = [ flushPrevContextMap() ]; | ||
var traversalStore = [ flushPrevContextStore() ]; | ||
var traversalErrorFrame = [ getCurrentErrorFrame() ]; | ||
if (visitLoop(traversalChildren, traversalMap, traversalStore, traversalErrorFrame, queue, visitor)) { | ||
queue.unshift(makeYieldFrame(traversalChildren, traversalMap, traversalStore, traversalErrorFrame)); | ||
} | ||
}; | ||
function wrapWithDispatcher(exec) { | ||
return function() { | ||
var args = [], len = arguments.length; | ||
while (len--) { | ||
args[len] = arguments[len]; | ||
var update$3 = function(frame, queue, visitor) { | ||
if ("frame.yield" === frame.kind) { | ||
setCurrentIdentity(null); | ||
setCurrentContextMap(frame.contextMap); | ||
setCurrentContextStore(frame.contextStore); | ||
setCurrentErrorFrame(frame.errorFrame); | ||
if (visitLoop(frame.traversalChildren, frame.traversalMap, frame.traversalStore, frame.traversalErrorFrame, queue, visitor)) { | ||
queue.unshift(makeYieldFrame(frame.traversalChildren, frame.traversalMap, frame.traversalStore, frame.traversalErrorFrame)); | ||
} | ||
} else { | ||
var prevDispatcher = ReactCurrentDispatcher.current; | ||
var children = null; | ||
ReactCurrentDispatcher.current = Dispatcher; | ||
try { | ||
ReactCurrentDispatcher.current = Dispatcher; | ||
return exec.apply(void 0, args); | ||
if ("frame.class" === frame.kind) { | ||
children = function(queue, frame) { | ||
setCurrentIdentity(null); | ||
setCurrentContextMap(frame.contextMap); | ||
setCurrentContextStore(frame.contextStore); | ||
setCurrentErrorFrame(frame.errorFrame); | ||
if (frame.error) { | ||
if (++frame.instance.updater._thrown >= 25) { | ||
return null; | ||
} | ||
frame.instance._isMounted = !0; | ||
if ("function" == typeof frame.instance.componentDidCatch) { | ||
frame.instance.componentDidCatch(frame.error); | ||
} | ||
if ("function" == typeof frame.type.getDerivedStateFromError) { | ||
frame.instance.updater.enqueueSetState(frame.instance, frame.type.getDerivedStateFromError(frame.error)); | ||
} | ||
} | ||
return render$2(frame.type, frame.instance, queue); | ||
}(queue, frame); | ||
} else if ("frame.hooks" === frame.kind) { | ||
children = function(queue, frame) { | ||
setFirstHook(frame.hook); | ||
setCurrentIdentity(frame.id); | ||
setCurrentContextMap(frame.contextMap); | ||
setCurrentContextStore(frame.contextStore); | ||
setCurrentErrorFrame(frame.errorFrame); | ||
return render$1(frame.type, frame.props, queue); | ||
}(queue, frame); | ||
} else if ("frame.lazy" === frame.kind) { | ||
children = function(queue, frame) { | ||
setCurrentIdentity(null); | ||
setCurrentContextMap(frame.contextMap); | ||
setCurrentContextStore(frame.contextStore); | ||
setCurrentErrorFrame(frame.errorFrame); | ||
return render(frame.type, frame.props); | ||
}(0, frame); | ||
} | ||
} catch (error) { | ||
var errorFrame = getCurrentErrorFrame(); | ||
if (!errorFrame) { | ||
throw error; | ||
} | ||
errorFrame.error = error; | ||
queue.unshift(errorFrame); | ||
children = null; | ||
} finally { | ||
ReactCurrentDispatcher.current = prevDispatcher; | ||
} | ||
}; | ||
} | ||
var resumeWithDispatcher = wrapWithDispatcher((function(frame, queue, visitor) { | ||
setCurrentIdentity(null); | ||
setCurrentContextMap(frame.contextMap); | ||
setCurrentContextStore(frame.contextStore); | ||
if (visitLoop(frame.children, frame.map, frame.store, queue, visitor)) { | ||
queue.unshift(makeYieldFrame(frame.children, frame.map, frame.store)); | ||
visit(getChildrenArray(children), queue, visitor); | ||
} | ||
})); | ||
}; | ||
var visitWithDispatcher = wrapWithDispatcher((function(init, queue, visitor) { | ||
var traversalChildren = [ init ]; | ||
var traversalMap = [ flushPrevContextMap() ]; | ||
var traversalStore = [ flushPrevContextStore() ]; | ||
if (visitLoop(traversalChildren, traversalMap, traversalStore, queue, visitor)) { | ||
queue.unshift(makeYieldFrame(traversalChildren, traversalMap, traversalStore)); | ||
} | ||
})); | ||
function _ref$2(resolve, reject) { | ||
setImmediate(resolve); | ||
} | ||
var updateWithDispatcher = wrapWithDispatcher((function(frame, queue) { | ||
switch (frame.kind) { | ||
case "frame.class": | ||
return function(queue, frame) { | ||
setCurrentIdentity(null); | ||
setCurrentContextMap(frame.contextMap); | ||
setCurrentContextStore(frame.contextStore); | ||
return render$2(frame.type, frame.instance, queue); | ||
}(queue, frame); | ||
case "frame.hooks": | ||
return function(queue, frame) { | ||
setFirstHook(frame.hook); | ||
setCurrentIdentity(frame.id); | ||
setCurrentContextMap(frame.contextMap); | ||
setCurrentContextStore(frame.contextStore); | ||
return render$1(frame.type, frame.props, queue); | ||
}(queue, frame); | ||
case "frame.lazy": | ||
return function(queue, frame) { | ||
setCurrentIdentity(null); | ||
setCurrentContextMap(frame.contextMap); | ||
setCurrentContextStore(frame.contextStore); | ||
return render(frame.type, frame.props); | ||
}(0, frame); | ||
default: | ||
return []; | ||
} | ||
})); | ||
var flushFrames = function(queue, visitor) { | ||
var frame = queue.shift(); | ||
return frame ? function(frame, queue, visitor) { | ||
if ("frame.yield" === frame.kind) { | ||
return new Promise((function _ref(resolve, reject) { | ||
var resume = function() { | ||
try { | ||
resumeWithDispatcher(frame, queue, visitor); | ||
resolve(); | ||
} catch (err) { | ||
reject(err); | ||
} | ||
}; | ||
if (SHOULD_YIELD) { | ||
setImmediate(resume); | ||
} else { | ||
resume(); | ||
} | ||
})); | ||
if (!frame) { | ||
return Promise.resolve(); | ||
} | ||
if (SHOULD_YIELD && "frame.yield" === frame.kind) { | ||
frame.thenable = new Promise(_ref$2); | ||
} | ||
return Promise.resolve(frame.thenable).then((function() { | ||
update$3(frame, queue, visitor); | ||
return flushFrames(queue, visitor); | ||
}), (function(error) { | ||
if (!frame.errorFrame) { | ||
throw error; | ||
} | ||
return frame.thenable.then((function() { | ||
var children = updateWithDispatcher(frame, queue); | ||
visitWithDispatcher(getChildrenArray(children), queue, visitor); | ||
})); | ||
}(frame, queue, visitor).then((function() { | ||
return flushFrames(queue, visitor); | ||
})) : Promise.resolve(); | ||
frame.errorFrame.error = error; | ||
update$3(frame.errorFrame, queue, visitor); | ||
})); | ||
}; | ||
@@ -783,13 +880,16 @@ | ||
module.exports = function(element, visitor) { | ||
if (!visitor) { | ||
visitor = defaultVisitor; | ||
} | ||
var queue = []; | ||
var fn = void 0 !== visitor ? visitor : defaultVisitor; | ||
setCurrentContextMap({}); | ||
setCurrentContextStore(new Map); | ||
setCurrentErrorFrame(null); | ||
try { | ||
visitWithDispatcher(getChildrenArray(element), queue, fn); | ||
visit(getChildrenArray(element), queue, visitor); | ||
} catch (error) { | ||
return Promise.reject(error); | ||
} | ||
return flushFrames(queue, fn); | ||
return flushFrames(queue, visitor); | ||
}; | ||
//# sourceMappingURL=react-ssr-prepass.development.js.map |
@@ -1,2 +0,2 @@ | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var e=require("react"),n=t(e),r=require("react-is"),u=t(require("object-is"));function o(){return(o=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n,r=arguments[e];for(n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}var c=r.Element,i=r.Portal,l=r.Fragment,a=r.StrictMode,f=r.Profiler,s=r.ContextProvider,p=r.ContextConsumer,d=r.ConcurrentMode,h=r.ForwardRef,y=r.Suspense,m=r.Memo,v=r.Lazy,x=e.Children.toArray,_=function(t){return null!==t&&"object"==typeof t},S=function(t){return x(t).filter(_)},M=function(t,e){return"object"==typeof e?o({},e,t):t},g=new Map,b={},w=void 0,C=void 0,E=function(){return o({},b)},P=function(){return new Map(g)},k=function(){var t=w;return w=void 0,t},q=function(){var t=C;return C=void 0,t},z=function(t){void 0!==t&&o(b,t)},j=function(t){void 0!==t&&g.set(t[0],t[1])},D=function(t){w=void 0,b=t},F=function(t){C=void 0,g=t},R=function(t){var e=g.get(t);return void 0!==e?e:t._currentValue},W={},U=function(t){var e=t.contextType;if(t=t.contextTypes,e)return R(e);if(!t)return W;for(var n in e={},t)e[n]=b[n];return e},O=null,T=function(t){O=t},I=function(){if(null===O)throw Error("[react-ssr-prepass] Hooks can only be called inside the body of a function component. (https://fb.me/react-invalid-hook-call)");return O},N=null,A=null,L=!1,$=null,V=0,H=function(t){N=t};function B(){return null===A?null===N?N=A={memoizedState:null,queue:null,next:null}:A=N:A=null===A.next?A.next={memoizedState:null,queue:null,next:null}:A.next}function Y(t,e){return"function"==typeof e?e(t):e}function G(t,e,n){var r=I();if(null===(A=B()).queue&&(e=t===Y?"function"==typeof e?e():e:void 0!==n?n(e):e,A.memoizedState=e),r=(e=A.queue||(A.queue={last:null,dispatch:null})).dispatch||(e.dispatch=K.bind(null,r,e)),null!==$&&void 0!==(n=$.get(e))){$.delete(e),e=A.memoizedState;do{e=t(e,n.action),n=n.next}while(null!==n);A.memoizedState=e}return[A.memoizedState,r]}function J(t,e){I(),e=void 0===e?null:e;var n=(A=B()).memoizedState;return null!==n&&null!==e&&function(t,e){if(null===e)return!1;for(var n=0;n<e.length&&n<t.length;n++)if(!u(t[n],e[n]))return!1;return!0}(e,n[1])?n[0]:(t=t(),A.memoizedState=[t,e],t)}function K(t,e,n){if(t===O)if(L=!0,t={action:n,next:null},null===$&&($=new Map),void 0===(n=$.get(e)))$.set(e,t);else{for(e=n;null!==e.next;)e=e.next;e.next=t}}function Q(){}function X(t){t()}var Z={readContext:function(t,e){return R(t)},useContext:function(t,e){return I(),R(t)},useMemo:J,useReducer:G,useRef:function(t){I();var e=(A=B()).memoizedState;return null===e?A.memoizedState=t={current:t}:e},useState:function(t){return G(Y,t)},useCallback:function(t,e){return J((function(){return t}),e)},useTransition:function(){return[X,!1]},useDeferredValue:function(t){return t},useLayoutEffect:Q,useImperativeHandle:Q,useEffect:Q,useDebugValue:Q},tt=function(t){return t._status=0,t._ctor().then((function(e){"function"==typeof e?(t._result=e,t._status=1):null!==e&&"object"==typeof e&&"function"==typeof e.default?(t._result=e.default,t._status=1):t._status=2})).catch((function(){t._status=2}))},et=function(t,n,r){return 1===t._status?e.createElement(t._result,n):null},nt=function(t,e,n){return{contextMap:E(),contextStore:P(),id:I(),hook:N,kind:"frame.hooks",thenable:n,props:e,type:t}},rt=function(t,e,n){try{return function(t,e,n){A=null;for(var r=t(e,n);V<25&&L;)L=!1,V+=1,A=null,r=t(e,n);return V=0,A=$=null,r}(t,M(e,t.defaultProps),U(t))}catch(r){if("function"!=typeof r.then)throw r;return n.push(nt(t,e,r)),null}};function ut(){return!1}function ot(){return null}var ct=function(t,e,n){return{contextMap:E(),contextStore:P(),thenable:n,kind:"frame.class",instance:e,type:t}},it=function(t,e,n){!function(t){var e=t.updater.queue;if(0<e.length){for(var n=o({},t.state),r=0,u=e.length;r<u;r++){var c=e[r];null!==(c="function"==typeof c?c.call(t,n,t.props,t.context):c)&&o(n,c)}t.state=n,e.length=0}}(e);var r=null;try{r=e.render()}catch(r){if("function"!=typeof r.then)throw r;return n.push(ct(t,e,r)),null}if(void 0!==t.childContextTypes&&"function"==typeof e.getChildContext&&null!==(t=e.getChildContext())&&"object"==typeof t&&function(t){for(var e in w={},t)w[e]=b[e],b[e]=t[e]}(t),"function"!=typeof e.getDerivedStateFromProps&&("function"==typeof e.componentWillMount||"function"==typeof e.UNSAFE_componentWillMount)&&"function"==typeof e.componentWillUnmount)try{e.componentWillUnmount()}catch(t){}return e._isMounted=!1,r},lt="function"==typeof setImmediate,at=function(t,n,r){switch(function(t){switch(t.$$typeof){case i:return i;case c:switch(t.type){case d:return d;case l:return l;case f:return f;case a:return a;case y:return y;default:switch(t.type&&t.type.$$typeof){case v:return v;case m:return m;case p:return p;case s:return s;case h:return h;default:return c}}}}(t)){case y:case a:case d:case f:case l:return S(t.props.children);case s:return r=(n=t.props).children,function(t,e){C=[t,g.get(t)],g.set(t,e)}(t.type._context,n.value),S(r);case p:return"function"==typeof(n=t.props.children)?(t=R("object"==typeof(t=t.type)._context?t._context:t),S(n(t))):[];case v:return t=function(t,e,n){return 2!==t._status&&1!==t._status?(n.push({contextMap:E(),contextStore:P(),kind:"frame.lazy",thenable:tt(t),props:e,type:t}),null):et(t,e)}(t.type,t.props,n),S(t);case m:return t=e.createElement(t.type.type,t.props),S(t);case h:return n=(r=t.type).render,t=M(t.props,r.defaultProps),t=e.createElement(n,t),S(t);case c:return"string"==typeof t.type?S(t.props.children):(t=function(t,e,n,r,u){return function(t){return t.prototype&&t.prototype.isReactComponent}(t)?function(t,e,n,r,u){return T(null),(r=r(u,e=function(t,e){var n=function(){var t=[];return{queue:t,isMounted:ut,enqueueForceUpdate:ot,enqueueReplaceState:function(e,n){e._isMounted&&(t.length=0,t.push(n))},enqueueSetState:function(e,n){e._isMounted&&t.push(n)}}}(),r=M(e,t.defaultProps),u=U(t);return(e=new t(r,u,n)).props=r,e.context=u,e.updater=n,e._isMounted=!0,void 0===e.state&&(e.state=null),"function"==typeof t.getDerivedStateFromProps?null!=(t=(t=t.getDerivedStateFromProps)(e.props,e.state))&&(e.state=o({},e.state,t)):"function"==typeof e.componentWillMount?e.componentWillMount():"function"==typeof e.UNSAFE_componentWillMount&&e.UNSAFE_componentWillMount(),e}(t,e)))?(n.push(ct(t,e,r)),null):it(t,e,n)}(t,e,n,r,u):function(t,e,n,r,u){return H(null),T({}),(r=r(u))?(n.push(nt(t,e,r)),null):rt(t,e,n)}(t,e,n,r,u)}(t.type,t.props,n,r,t),S(t));default:return[]}},ft=function(t,e,n,r,u){for(var o=Date.now();0<t.length;){var c=t[t.length-1].shift();if(void 0!==c?(c=at(c,r,u),t.push(c),e.push(k()),n.push(q())):(t.pop(),z(e.pop()),j(n.pop())),lt&&Date.now()-o>5)return!0}return!1},st=function(t,e,n){return{contextMap:E(),contextStore:P(),thenable:Promise.resolve(),kind:"frame.yield",children:t,map:e,store:n}},pt=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher;function dt(t){return function(){for(var e=[],n=arguments.length;n--;)e[n]=arguments[n];n=pt.current;try{return pt.current=Z,t.apply(void 0,e)}finally{pt.current=n}}}var ht=dt((function(t,e,n){T(null),D(t.contextMap),F(t.contextStore),ft(t.children,t.map,t.store,e,n)&&e.unshift(st(t.children,t.map,t.store))})),yt=dt((function(t,e,n){t=[t];var r=[k()],u=[q()];ft(t,r,u,e,n)&&e.unshift(st(t,r,u))})),mt=dt((function(t,e){switch(t.kind){case"frame.class":return function(t,e){return T(null),D(e.contextMap),F(e.contextStore),it(e.type,e.instance,t)}(e,t);case"frame.hooks":return function(t,e){return H(e.hook),T(e.id),D(e.contextMap),F(e.contextStore),rt(e.type,e.props,t)}(e,t);case"frame.lazy":return function(t,e){return T(null),D(e.contextMap),F(e.contextStore),et(e.type,e.props)}(0,t);default:return[]}})),vt=function(t,e){var n=t.shift();return n?function(t,e,n){return"frame.yield"===t.kind?new Promise((function(r,u){var o=function(){try{ht(t,e,n),r()}catch(t){u(t)}};lt?setImmediate(o):o()})):t.thenable.then((function(){var r=mt(t,e);yt(S(r),e,n)}))}(n,t,e).then((function(){return vt(t,e)})):Promise.resolve()},xt=function(){};module.exports=function(t,e){var n=[];e=void 0!==e?e:xt,D({}),F(new Map);try{yt(S(t),n,e)}catch(t){return Promise.reject(t)}return vt(n,e)}; | ||
"use strict";var t,e=require("react"),n=(t=e)&&"object"==typeof t&&"default"in t?t:{default:t};function r(){return(r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n,r=arguments[e];for(n in r)Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t}).apply(this,arguments)}var o=60103,u=60106,a=60107,c=60108,i=60114,l=60109,f=60110,s=60111,p=60112,d=60113,m=60115,y=60116;if("function"==typeof Symbol&&Symbol.for){var h=Symbol.for;o=h("react.element"),u=h("react.portal"),a=h("react.fragment"),c=h("react.strict_mode"),i=h("react.profiler"),l=h("react.provider"),f=h("react.context"),s=Symbol.for("react.concurrent_mode"),p=h("react.forward_ref"),d=h("react.suspense"),m=h("react.memo"),y=h("react.lazy")}var v=o,_=u,S=a,x=c,M=i,b=l,F=f,g=s,w=p,E=d,C=m,k=y,D=e.Children.toArray,P=function(t){return null!==t&&"object"==typeof t},j=function(t){return D(t).filter(P)},z=function(t,e){return"object"==typeof e?r({},e,t):t},q=new Map,O={},R=void 0,W=void 0,U=function(){return r({},O)},T=function(){return new Map(q)},I=function(){var t=R;return R=void 0,t},N=function(){var t=W;return W=void 0,t},A=function(t){void 0!==t&&r(O,t)},L=function(t){void 0!==t&&q.set(t[0],t[1])},$=function(t){R=void 0,O=t},V=function(t){W=void 0,q=t},H=function(t){var e=q.get(t);return void 0!==e?e:t._currentValue},B={},Y=function(t){var e=t.contextType;if(t=t.contextTypes,e)return H(e);if(!t)return B;for(var n in e={},t)e[n]=O[n];return e},G=null,J=function(){return G},K=function(t){G=t||null},Q="function"==typeof Object.is?Object.is:function(t,e){return t===e&&(0!==t||1/t==1/e)||t!=t&&e!=e},X=null,Z=function(t){X=t},tt=function(){if(null===X)throw Error("[react-ssr-prepass] Hooks can only be called inside the body of a function component. (https://fb.me/react-invalid-hook-call)");return X},et=null,nt=null,rt=!1,ot=null,ut=0,at=function(t){et=t};function ct(){return null===nt?null===et?et=nt={memoizedState:null,queue:null,next:null}:nt=et:nt=null===nt.next?nt.next={memoizedState:null,queue:null,next:null}:nt.next}function it(t,e){return"function"==typeof e?e(t):e}function lt(t,e,n){var r=tt();if(null===(nt=ct()).queue&&(e=t===it?"function"==typeof e?e():e:void 0!==n?n(e):e,nt.memoizedState=e),r=(e=nt.queue||(nt.queue={last:null,dispatch:null})).dispatch||(e.dispatch=st.bind(null,r,e)),null!==ot&&void 0!==(n=ot.get(e))){ot.delete(e),e=nt.memoizedState;do{e=t(e,n.action),n=n.next}while(null!==n);nt.memoizedState=e}return[nt.memoizedState,r]}function ft(t,e){tt(),e=void 0===e?null:e;var n=(nt=ct()).memoizedState;return null!==n&&null!==e&&function(t,e){if(null===e)return!1;for(var n=0;n<e.length&&n<t.length;n++)if(!Q(t[n],e[n]))return!1;return!0}(e,n[1])?n[0]:(t=t(),nt.memoizedState=[t,e],t)}function st(t,e,n){if(t===X)if(rt=!0,t={action:n,next:null},null===ot&&(ot=new Map),void 0===(n=ot.get(e)))ot.set(e,t);else{for(e=n;null!==e.next;)e=e.next;e.next=t}}function pt(){}function dt(t){t()}var mt={readContext:function(t,e){return H(t)},useContext:function(t,e){return tt(),H(t)},useMemo:ft,useReducer:lt,useRef:function(t){tt();var e=(nt=ct()).memoizedState;return null===e?nt.memoizedState=t={current:t}:e},useState:function(t){return lt(it,t)},useCallback:function(t,e){return ft((function(){return t}),e)},useTransition:function(){return[dt,!1]},useDeferredValue:function(t){return t},useLayoutEffect:pt,useImperativeHandle:pt,useEffect:pt,useDebugValue:pt},yt=function(t){var e=t._payload||t;return 0===e._status?e._result:1===e._status?Promise.resolve(e._result):2===e._status?Promise.reject(e._result):(e._status=0,e._result=(e._ctor||e._result)().then((function(t){e._result=t,"function"==typeof t?e._status=1:null!==t&&"object"==typeof t&&"function"==typeof t.default?(e._result=t.default,e._status=1):e._status=2})).catch((function(t){return e._status=2,e._result=t,Promise.reject(t)})))},ht=function(t,n,r){return 1===(t=t._payload||t)._status?e.createElement(t._result,n):null},vt=function(t,e,n){return{contextMap:U(),contextStore:T(),id:tt(),hook:et,kind:"frame.hooks",errorFrame:J(),thenable:n,props:e,type:t}},_t=function(t,e,n){try{return function(t,e,n){nt=null;for(var r=t(e,n);ut<25&&rt;)rt=!1,ut+=1,nt=null,r=t(e,n);return ut=0,nt=ot=null,r}(t,z(e,t.defaultProps),Y(t))}catch(r){if("function"!=typeof r.then)throw r;return n.push(vt(t,e,r)),null}};function St(){return!1}function xt(){return null}var Mt=function(t,e,n){return{contextMap:U(),contextStore:T(),errorFrame:J(),thenable:n,kind:"frame.class",error:null,instance:e,type:t}},bt=function(t,e,n){!function(t){var e=t.updater.queue;if(0<e.length){for(var n=r({},t.state),o=0,u=e.length;o<u;o++){var a=e[o];null!==(a="function"==typeof a?a.call(t,n,t.props,t.context):a)&&r(n,a)}t.state=n,e.length=0}}(e);var o=null;try{o=e.render()}catch(r){if("function"!=typeof r.then)throw r;return n.push(Mt(t,e,r)),null}if(void 0!==t.childContextTypes&&"function"==typeof e.getChildContext&&null!==(t=e.getChildContext())&&"object"==typeof t&&function(t){for(var e in R={},t)R[e]=O[e],O[e]=t[e]}(t),"function"!=typeof e.getDerivedStateFromProps&&("function"==typeof e.componentWillMount||"function"==typeof e.UNSAFE_componentWillMount)&&"function"==typeof e.componentWillUnmount)try{e.componentWillUnmount()}catch(t){}return e._isMounted=!1,o},Ft=n.default.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher,gt="function"==typeof setImmediate,wt=function(t,n,o){switch(function(t){switch(t.$$typeof){case _:return _;case v:switch(t.type){case g:return g;case S:return S;case M:return M;case x:return x;case E:return E;default:switch(t.type&&t.type.$$typeof){case k:return k;case C:return C;case F:return F;case b:return b;case w:return w;default:return v}}}}(t)){case E:case x:case g:case M:case S:return j(t.props.children);case b:return o=(n=t.props).children,function(t,e){W=[t,q.get(t)],q.set(t,e)}(t.type._context,n.value),j(o);case F:return"function"==typeof(n=t.props.children)?(t=H("object"==typeof(t=t.type)._context?t._context:t),j(n(t))):[];case k:return t=function(t,e,n){return 0>=(t._payload||t)._status?(n.push({kind:"frame.lazy",contextMap:U(),contextStore:T(),errorFrame:J(),thenable:yt(t),props:e,type:t}),null):ht(t,e)}(t.type,t.props,n),j(t);case C:return t=e.createElement(t.type.type,t.props),j(t);case w:return n=(o=t.type).render,t=z(t.props,o.defaultProps),t=e.createElement(n,t),j(t);case v:return"string"==typeof t.type?j(t.props.children):(t=function(t,e,n,o,u){return function(t){return t.prototype&&t.prototype.isReactComponent}(t)?function(t,e,n,o,u){return Z(null),(o=o(u,e=function(t,e){var n=function(){var t=[];return{_thrown:0,queue:t,isMounted:St,enqueueForceUpdate:xt,enqueueReplaceState:function(e,n){e._isMounted&&(t.length=0,t.push(n))},enqueueSetState:function(e,n){e._isMounted&&t.push(n)}}}(),o=z(e,t.defaultProps),u=Y(t);return(e=new t(o,u,n)).props=o,e.context=u,e.updater=n,e._isMounted=!0,void 0===e.state&&(e.state=null),"function"!=typeof e.componentDidCatch&&"function"!=typeof t.getDerivedStateFromError||((n=Mt(t,e,null)).errorFrame=n,K(n)),"function"==typeof t.getDerivedStateFromProps?null!=(t=(t=t.getDerivedStateFromProps)(e.props,e.state))&&(e.state=r({},e.state,t)):"function"==typeof e.componentWillMount?e.componentWillMount():"function"==typeof e.UNSAFE_componentWillMount&&e.UNSAFE_componentWillMount(),e}(t,e)))?(n.push(Mt(t,e,o)),null):bt(t,e,n)}(t,e,n,o,u):function(t,e,n,r,o){return at(null),Z({}),(r=r(o))?(n.push(vt(t,e,r)),null):_t(t,e,n)}(t,e,n,o,u)}(t.type,t.props,n,o,t),j(t));default:return[]}},Et=function(t,e,n,r,o,u){var a=Ft.current,c=Date.now();try{for(Ft.current=mt;0<t.length;){var i=t[t.length-1].shift();if(void 0!==i){var l=wt(i,o,u);t.push(l),e.push(I()),n.push(N()),r.push(J())}else t.pop(),A(e.pop()),L(n.pop()),K(r.pop());if(gt&&Date.now()-c>5)return!0}return!1}catch(t){var f=J();if(!f)throw t;return f.error=t,o.unshift(f),!1}finally{Ft.current=a}},Ct=function(t,e,n,r){return{contextMap:U(),contextStore:T(),errorFrame:J(),thenable:null,kind:"frame.yield",traversalChildren:t,traversalMap:e,traversalStore:n,traversalErrorFrame:r}},kt=function(t,e,n){t=[t];var r=[I()],o=[N()],u=[J()];Et(t,r,o,u,e,n)&&e.unshift(Ct(t,r,o,u))},Dt=function(t,e,n){if("frame.yield"===t.kind)Z(null),$(t.contextMap),V(t.contextStore),K(t.errorFrame),Et(t.traversalChildren,t.traversalMap,t.traversalStore,t.traversalErrorFrame,e,n)&&e.unshift(Ct(t.traversalChildren,t.traversalMap,t.traversalStore,t.traversalErrorFrame));else{var r=Ft.current,o=null;Ft.current=mt;try{"frame.class"===t.kind?o=function(t,e){if(Z(null),$(e.contextMap),V(e.contextStore),K(e.errorFrame),e.error){if(++e.instance.updater._thrown>=25)return null;e.instance._isMounted=!0,"function"==typeof e.instance.componentDidCatch&&e.instance.componentDidCatch(e.error),"function"==typeof e.type.getDerivedStateFromError&&e.instance.updater.enqueueSetState(e.instance,e.type.getDerivedStateFromError(e.error))}return bt(e.type,e.instance,t)}(e,t):"frame.hooks"===t.kind?o=function(t,e){return at(e.hook),Z(e.id),$(e.contextMap),V(e.contextStore),K(e.errorFrame),_t(e.type,e.props,t)}(e,t):"frame.lazy"===t.kind&&(o=function(t,e){return Z(null),$(e.contextMap),V(e.contextStore),K(e.errorFrame),ht(e.type,e.props)}(0,t))}catch(t){var u=J();if(!u)throw t;u.error=t,e.unshift(u),o=null}finally{Ft.current=r}kt(j(o),e,n)}};function Pt(t,e){setImmediate(t)}var jt=function(t,e){var n=t.shift();return n?(gt&&"frame.yield"===n.kind&&(n.thenable=new Promise(Pt)),Promise.resolve(n.thenable).then((function(){return Dt(n,t,e),jt(t,e)}),(function(r){if(!n.errorFrame)throw r;n.errorFrame.error=r,Dt(n.errorFrame,t,e)}))):Promise.resolve()},zt=function(){};module.exports=function(t,e){e||(e=zt);var n=[];$({}),V(new Map),K(null);try{kt(j(t),n,e)}catch(t){return Promise.reject(t)}return jt(n,e)}; | ||
//# sourceMappingURL=react-ssr-prepass.production.min.js.map |
{ | ||
"name": "react-ssr-prepass", | ||
"version": "1.2.1", | ||
"version": "1.3.0-rc.0", | ||
"description": "A custom partial React SSR renderer for prefetching and suspense", | ||
@@ -38,7 +38,2 @@ "main": "index.js", | ||
}, | ||
"jest": { | ||
"globals": { | ||
"__DEV__": true | ||
} | ||
}, | ||
"lint-staged": { | ||
@@ -59,36 +54,31 @@ "**/*.js": [ | ||
"peerDependencies": { | ||
"react": "^16.8.0", | ||
"react-is": "^16.8.0" | ||
"react": "^16.8.0 || ^17.0.0" | ||
}, | ||
"dependencies": { | ||
"object-is": "^1.1.2" | ||
}, | ||
"devDependencies": { | ||
"@ampproject/rollup-plugin-closure-compiler": "^0.25.2", | ||
"@babel/core": "^7.9.0", | ||
"@babel/plugin-transform-flow-strip-types": "^7.9.0", | ||
"@babel/plugin-transform-object-assign": "^7.8.3", | ||
"@babel/preset-env": "^7.9.5", | ||
"@babel/preset-flow": "^7.9.0", | ||
"@babel/preset-react": "^7.9.4", | ||
"@ampproject/rollup-plugin-closure-compiler": "^0.26.0", | ||
"@babel/core": "^7.12.3", | ||
"@babel/plugin-transform-flow-strip-types": "^7.12.1", | ||
"@babel/plugin-transform-object-assign": "^7.12.1", | ||
"@babel/preset-env": "^7.12.1", | ||
"@babel/preset-flow": "^7.12.1", | ||
"@babel/preset-react": "^7.12.5", | ||
"@rollup/plugin-buble": "^0.21.3", | ||
"@rollup/plugin-commonjs": "^11.1.0", | ||
"@rollup/plugin-node-resolve": "^7.1.3", | ||
"babel-plugin-closure-elimination": "^1.3.0", | ||
"@rollup/plugin-commonjs": "^16.0.0", | ||
"@rollup/plugin-node-resolve": "^10.0.0", | ||
"babel-plugin-closure-elimination": "^1.3.2", | ||
"babel-plugin-transform-async-to-promises": "^0.8.15", | ||
"codecov": "^3.6.5", | ||
"flow-bin": "^0.122.0", | ||
"husky": "^4.2.5", | ||
"jest": "^25.3.0", | ||
"lint-staged": "^10.1.3", | ||
"flow-bin": "0.122.0", | ||
"husky": "^4.3.0", | ||
"jest": "^26.6.3", | ||
"lint-staged": "^10.5.1", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.0.4", | ||
"react": "^16.13.1", | ||
"react-dom": "^16.13.1", | ||
"react-is": "^16.13.1", | ||
"rollup": "^2.6.1", | ||
"prettier": "^2.1.2", | ||
"react": "^17.0.1", | ||
"react-dom": "^17.0.1", | ||
"rollup": "^2.33.1", | ||
"rollup-plugin-babel": "^4.4.0", | ||
"rollup-plugin-replace": "^2.2.0", | ||
"rollup-plugin-terser": "^5.3.0" | ||
"rollup-plugin-terser": "^7.0.2" | ||
} | ||
} |
@@ -84,3 +84,3 @@ # react-ssr-prepass | ||
const renderApp = async App => { | ||
const renderApp = async (App) => { | ||
const element = createElement(App) | ||
@@ -117,26 +117,2 @@ await ssrPrepass(element) | ||
## Examples & Recipes | ||
### Usage with `react-apollo` | ||
Instead of using `react-apollo`'s own `getDataFromTree` function, `react-ssr-prepass` | ||
can be used instead. For this to work, we will have to write a visitor function | ||
that knows how to suspend on `react-apollo`'s `Query` component. | ||
Luckily this is quite simple, since all we need to do is call the `fetchData` | ||
method on the `Query` component's instance. | ||
```js | ||
ssrPrepass(<App />, (_element, instance) => { | ||
if (instance !== undefined && typeof instance.fetchData === 'function') { | ||
return instance.fetchData() | ||
} | ||
}) | ||
``` | ||
Since we're now calling `fetchData` when it exists, which returns a `Promise` | ||
already, `ssrPrepass` will suspend on `<Query>` components. | ||
[More information can be found in Apollo's own docs](https://www.apollographql.com/docs/react/features/server-side-rendering.html#getDataFromTree) | ||
## Prior Art | ||
@@ -143,0 +119,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
154781
1
25
824
3
131
+ Addedreact@17.0.2(transitive)
- Removedobject-is@^1.1.2
- Removedcall-bind@1.0.8(transitive)
- Removedcall-bind-apply-helpers@1.0.1(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddefine-properties@1.2.1(transitive)
- Removeddunder-proto@1.0.1(transitive)
- Removedes-define-property@1.0.1(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes-object-atoms@1.0.0(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.6(transitive)
- Removedgopd@1.2.0(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-symbols@1.1.0(transitive)
- Removedhasown@2.0.2(transitive)
- Removedmath-intrinsics@1.1.0(transitive)
- Removedobject-is@1.1.6(transitive)
- Removedobject-keys@1.1.1(transitive)
- Removedprop-types@15.8.1(transitive)
- Removedreact@16.14.0(transitive)
- Removedreact-is@16.13.1(transitive)
- Removedset-function-length@1.2.2(transitive)