UNPKG

next

Version:

The React Framework

70 lines (68 loc) 2.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); 0 && (module.exports = { dispatchAppRouterAction: null, useActionQueue: null }); function _export(target, all) { for(var name in all)Object.defineProperty(target, name, { enumerable: true, get: all[name] }); } _export(exports, { dispatchAppRouterAction: function() { return dispatchAppRouterAction; }, useActionQueue: function() { return useActionQueue; } }); const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard"); const _react = /*#__PURE__*/ _interop_require_wildcard._(require("react")); const _isthenable = require("../../shared/lib/is-thenable"); // The app router state lives outside of React, so we can import the dispatch // method directly wherever we need it, rather than passing it around via props // or context. let dispatch = null; function dispatchAppRouterAction(action) { if (dispatch === null) { throw Object.defineProperty(new Error('Internal Next.js error: Router action dispatched before initialization.'), "__NEXT_ERROR_CODE", { value: "E668", enumerable: false, configurable: true }); } dispatch(action); } function useActionQueue(actionQueue) { const [state, setState] = _react.default.useState(actionQueue.state); // Because of a known issue that requires to decode Flight streams inside the // render phase, we have to be a bit clever and assign the dispatch method to // a module-level variable upon initialization. The useState hook in this // module only exists to synchronize state that lives outside of React. // Ideally, what we'd do instead is pass the state as a prop to root.render; // this is conceptually how we're modeling the app router state, despite the // weird implementation details. if (process.env.NODE_ENV !== 'production') { const useSyncDevRenderIndicator = require('./react-dev-overlay/utils/dev-indicator/use-sync-dev-render-indicator').useSyncDevRenderIndicator; // eslint-disable-next-line react-hooks/rules-of-hooks const syncDevRenderIndicator = useSyncDevRenderIndicator(); dispatch = (action)=>{ syncDevRenderIndicator(()=>{ actionQueue.dispatch(action, setState); }); }; } else { dispatch = (action)=>actionQueue.dispatch(action, setState); } return (0, _isthenable.isThenable)(state) ? (0, _react.use)(state) : state; } if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') { Object.defineProperty(exports.default, '__esModule', { value: true }); Object.assign(exports.default, exports); module.exports = exports.default; } //# sourceMappingURL=use-action-queue.js.map