├── src
├── packages
│ ├── log
│ │ ├── README.md
│ │ ├── types.ts
│ │ ├── package.json
│ │ ├── index.ts
│ │ ├── renderTip
│ │ │ └── index.ts
│ │ └── utils.ts
│ ├── react-dom
│ │ ├── server.js
│ │ ├── test-utils.js
│ │ ├── server.node.js
│ │ ├── server.browser.js
│ │ ├── README.md
│ │ ├── LICENSE
│ │ ├── index.js
│ │ ├── profiling.js
│ │ ├── package.json
│ │ ├── cjs
│ │ │ └── react-dom-test-utils.production.min.js
│ │ └── umd
│ │ │ └── react-dom-test-utils.production.min.js
│ ├── react
│ │ ├── index.js
│ │ ├── jsx-runtime.js
│ │ ├── jsx-dev-runtime.js
│ │ ├── unstable-shared-subset.js
│ │ ├── cjs
│ │ │ ├── react-unstable-shared-subset.production.min.js
│ │ │ ├── react-jsx-dev-runtime.profiling.min.js
│ │ │ ├── react-jsx-dev-runtime.production.min.js
│ │ │ ├── react-unstable-shared-subset.development.js
│ │ │ ├── react-jsx-runtime.profiling.min.js
│ │ │ ├── react-jsx-runtime.production.min.js
│ │ │ └── react.production.min.js
│ │ ├── README.md
│ │ ├── LICENSE
│ │ ├── package.json
│ │ └── umd
│ │ │ ├── react.production.min.js
│ │ │ └── react.profiling.min.js
│ ├── scheduler
│ │ ├── index.js
│ │ ├── unstable_mock.js
│ │ ├── unstable_post_task.js
│ │ ├── README.md
│ │ ├── LICENSE
│ │ ├── cjs
│ │ │ ├── scheduler-unstable_post_task.production.min.js
│ │ │ ├── scheduler.production.min.js
│ │ │ ├── scheduler-unstable_mock.production.min.js
│ │ │ └── scheduler-unstable_post_task.development.js
│ │ ├── package.json
│ │ └── umd
│ │ │ ├── scheduler-unstable_mock.production.min.js
│ │ │ ├── scheduler.production.min.js
│ │ │ ├── scheduler.profiling.min.js
│ │ │ └── scheduler.development.js
│ └── react-cache
│ │ ├── index.js
│ │ ├── README.md
│ │ ├── LICENSE
│ │ ├── package.json
│ │ ├── cjs
│ │ ├── react-cache.production.min.js
│ │ └── react-cache.development.js
│ │ └── umd
│ │ ├── react-cache.production.min.js
│ │ └── react-cache.development.js
├── vite-env.d.ts
├── demo
│ ├── MiniSchedulePhase
│ │ ├── style.css
│ │ └── index.ts
│ ├── testDemo.tsx
│ ├── MiniDiff
│ │ ├── index.ts
│ │ └── diff.ts
│ ├── Performance
│ │ ├── demo1.tsx
│ │ ├── demo2.tsx
│ │ ├── demo3.tsx
│ │ └── demo4.tsx
│ ├── BaseScheduleDemo.tsx
│ ├── bailoutDemo.tsx
│ ├── DiffDemo
│ │ ├── v1.tsx
│ │ ├── v3.tsx
│ │ ├── v2.tsx
│ │ └── v4.tsx
│ ├── MiniEventSystem
│ │ ├── index.tsx
│ │ └── eventSystem.ts
│ ├── SuspenseDemo
│ │ ├── utils.ts
│ │ ├── demo2.tsx
│ │ └── demo1.tsx
│ ├── TransitionDemo
│ │ ├── demo1.tsx
│ │ ├── demo3.tsx
│ │ └── demo2.tsx
│ ├── SSRDemo
│ │ └── index.tsx
│ ├── BailoutDemo
│ │ ├── step1.tsx
│ │ └── step2.tsx
│ ├── ContextDemo.tsx
│ ├── RenderPhaseDemo.tsx
│ ├── batchDemo.tsx
│ ├── longTaskDemo.tsx
│ ├── UseEffectDemo
│ │ └── index.tsx
│ ├── CommitPhaseDemo.tsx
│ ├── ErrorCatchDemo.tsx
│ └── MiniUseState
│ │ └── index.ts
├── main.tsx
└── globalLog.ts
├── .gitignore
├── README.md
├── server
├── entry.js
└── index.js
├── bin
└── runDEV.js
├── index.html
├── package.json
├── tsconfig.json
└── vite.config.ts
/src/packages/log/README.md:
--------------------------------------------------------------------------------
1 | 这个包是为了打印React内部信息用的
--------------------------------------------------------------------------------
/src/vite-env.d.ts:
--------------------------------------------------------------------------------
1 | ///
num is {num}
9 |耗时的组件
; 20 | } 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react18-demo", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "dev": "chokidar src/packages --initial --silent -c \"node ./bin/runDEV.js\"", 6 | "ssr": "node server", 7 | "build": "tsc && vite build", 8 | "serve": "vite preview" 9 | }, 10 | "devDependencies": { 11 | "@types/react": "^17.0.0", 12 | "@types/react-dom": "^17.0.0", 13 | "@vitejs/plugin-react-refresh": "^1.3.1", 14 | "chokidar-cli": "^3.0.0", 15 | "kill-port": "^1.6.1", 16 | "object-assign": "^4.1.1", 17 | "typescript": "^4.3.2", 18 | "vite": "^2.5.1" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/packages/react-cache/README.md: -------------------------------------------------------------------------------- 1 | # react-cache 2 | 3 | A basic cache for React applications. It also serves as a reference for more 4 | advanced caching implementations. 5 | 6 | This package is meant to be used alongside yet-to-be-released, experimental 7 | React features. It's unlikely to be useful in any other context. 8 | 9 | **Do not use in a real application.** We're publishing this early for 10 | demonstration purposes. 11 | 12 | **Use it at your own risk.** 13 | 14 | # No, Really, It Is Unstable 15 | 16 | The API ~~may~~ will change wildly between versions. 17 | 18 | 卡颂:当前版本(@2.0.0-alpha.1)实际是不兼容`React18`的,有些许修改 19 | -------------------------------------------------------------------------------- /src/demo/DiffDemo/v1.tsx: -------------------------------------------------------------------------------- 1 | import React, {useState} from 'react'; 2 | import {bindHook, getLibraryMethod, utils} from 'log'; 3 | 4 | const {log, COLOR: {SCHEDULE_COLOR, RENDER_COLOR, COMMIT_COLOR}} = utils; 5 | 6 | 7 | bindHook('placeChild', (type, fiber, lastPlacedIndex) => { 8 | log(RENDER_COLOR, `${type} lastPlacedIndex: ${lastPlacedIndex}`, fiber); 9 | }) 10 | 11 | // 用于调试 Diff算法 的Demo 12 | export default function App() { 13 | const [num, updateNum] = useState(0); 14 | 15 | return ( 16 |
14 | Edit {num}
15 | {Array(33).fill(3).map((_, i) =>
num is {num}
17 | > 18 | ) 19 | } 20 | 21 | export default function App() { 22 | 23 | return ( 24 | <> 25 | 26 |耗时的组件
; 37 | } 38 | -------------------------------------------------------------------------------- /src/demo/ContextDemo.tsx: -------------------------------------------------------------------------------- 1 | import React, {useState, useId, useContext, ReactNode} from 'react'; 2 | import {bindHook, utils} from 'log'; 3 | 4 | const {log, COLOR: {SCHEDULE_COLOR, RENDER_COLOR, COMMIT_COLOR}} = utils; 5 | 6 | 7 | 8 | const Ctx = React.createContext(0); 9 | 10 | const NumProvider = ({children}: {children: ReactNode}) => { 11 | const [num, add] = useState(0); 12 | 13 | return ( 14 |{num}
; 41 | } -------------------------------------------------------------------------------- /src/demo/Performance/demo3.tsx: -------------------------------------------------------------------------------- 1 | import React, {useState, useEffect, useContext} from 'react'; 2 | 3 | const numCtx = React.createContextnum is: {num}
; 40 | } 41 | -------------------------------------------------------------------------------- /src/packages/react/cjs/react-jsx-runtime.profiling.min.js: -------------------------------------------------------------------------------- 1 | /** @license React vundefined 2 | * react-jsx-runtime.profiling.min.js 3 | * 4 | * Copyright (c) Facebook, Inc. and its affiliates. 5 | * 6 | * This source code is licensed under the MIT license found in the 7 | * LICENSE file in the root directory of this source tree. 8 | */ 9 | 'use strict';require("object-assign");var f=require("react"),g=60103;exports.Fragment=60107;if("function"===typeof Symbol&&Symbol.for){var h=Symbol.for;g=h("react.element");exports.Fragment=h("react.fragment")}var m=Object.prototype.hasOwnProperty,n=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0}; 10 | function q(c,a,k){var b,d={},e=null,l=null;void 0!==k&&(e=""+k);void 0!==a.key&&(e=""+a.key);void 0!==a.ref&&(l=a.ref);for(b in a)m.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)void 0===d[b]&&(d[b]=a[b]);return{$$typeof:g,type:c,key:e,ref:l,props:d,_owner:n.current}}exports.jsx=q;exports.jsxs=q; 11 | -------------------------------------------------------------------------------- /src/packages/react/cjs/react-jsx-runtime.production.min.js: -------------------------------------------------------------------------------- 1 | /** @license React vundefined 2 | * react-jsx-runtime.production.min.js 3 | * 4 | * Copyright (c) Facebook, Inc. and its affiliates. 5 | * 6 | * This source code is licensed under the MIT license found in the 7 | * LICENSE file in the root directory of this source tree. 8 | */ 9 | 'use strict';require("object-assign");var f=require("react"),g=60103;exports.Fragment=60107;if("function"===typeof Symbol&&Symbol.for){var h=Symbol.for;g=h("react.element");exports.Fragment=h("react.fragment")}var m=Object.prototype.hasOwnProperty,n=f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0}; 10 | function q(c,a,k){var b,d={},e=null,l=null;void 0!==k&&(e=""+k);void 0!==a.key&&(e=""+a.key);void 0!==a.ref&&(l=a.ref);for(b in a)m.call(a,b)&&!p.hasOwnProperty(b)&&(d[b]=a[b]);if(c&&c.defaultProps)for(b in a=c.defaultProps,a)void 0===d[b]&&(d[b]=a[b]);return{$$typeof:g,type:c,key:e,ref:l,props:d,_owner:n.current}}exports.jsx=q;exports.jsxs=q; 11 | -------------------------------------------------------------------------------- /src/main.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './globalLog'; 4 | // import App from './demo/SuspenseDemo/demo2' 5 | // import './demo/SchedulerDemo'; 6 | // import App from './demo/BaseScheduleDemo'; 7 | // import App from './demo/LongTaskDemo'; 8 | // import App from './demo/BaseScheduleDemo'; 9 | // import App from './demo/testDemo'; 10 | // import App from './demo/bailoutDemo'; 11 | // import App from './demo/ContextDemo'; 12 | // import App from './demo/BailoutDemo/step1'; 13 | // import App from './demo/DiffDemo/v4'; 14 | // import App from './demo/Performance/demo2'; 15 | import App from './demo/ErrorCatchDemo'; 16 | // import App from './demo/TransitionDemo/demo3'; 17 | 18 | 19 | const rootEle = document.getElementById('root'); 20 | 21 | // import './demo/MiniUpdate2State'; 22 | // import './demo/MiniDiff'; 23 | // import './demo/MiniUseState'; 24 | // import './demo/MiniSchedulePhase'; 25 | 26 | rootEle && ReactDOM.createRoot(rootEle).render(num is {num}
17 | {children} 18 |耗时的组件
; 37 | } 38 | -------------------------------------------------------------------------------- /src/packages/react-dom/README.md: -------------------------------------------------------------------------------- 1 | # `react-dom` 2 | 3 | This package serves as the entry point to the DOM and server renderers for React. It is intended to be paired with the generic React package, which is shipped as `react` to npm. 4 | 5 | ## Installation 6 | 7 | ```sh 8 | npm install react react-dom 9 | ``` 10 | 11 | ## Usage 12 | 13 | ### In the browser 14 | 15 | ```js 16 | var React = require('react'); 17 | var ReactDOM = require('react-dom'); 18 | 19 | function MyComponent() { 20 | returnnum is {num}
31 | > 32 | ) 33 | } 34 | 35 | 36 | function ExpensiveCpn() { 37 | let now = performance.now(); 38 | while (performance.now() - now < 100) {} 39 | console.log('耗时的组件 render'); 40 | return耗时的组件
; 55 | } -------------------------------------------------------------------------------- /src/packages/react-cache/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "_from": "react-cache", 3 | "_id": "react-cache@2.0.0-alpha.1", 4 | "_inBundle": false, 5 | "_integrity": "sha512-dDJVVGvxAlZE/dMxDXaxU5ZfcE4fbaSmJVFrCTi6dYWXDp7YjCsnywkpEYG6IURVW+eJrCydAIDcW0FADw0/5w==", 6 | "_location": "/react-cache", 7 | "_phantomChildren": {}, 8 | "_requested": { 9 | "type": "tag", 10 | "registry": true, 11 | "raw": "react-cache", 12 | "name": "react-cache", 13 | "escapedName": "react-cache", 14 | "rawSpec": "", 15 | "saveSpec": null, 16 | "fetchSpec": "latest" 17 | }, 18 | "_requiredBy": [ 19 | "#DEV:/", 20 | "#USER" 21 | ], 22 | "_resolved": "https://registry.npmjs.org/react-cache/-/react-cache-2.0.0-alpha.1.tgz", 23 | "_shasum": "4c119188248bc988a61268458bc18bd845f2ec19", 24 | "_spec": "react-cache", 25 | "_where": "/Users/sc/Documents/react18-demo", 26 | "bugs": { 27 | "url": "https://github.com/facebook/react/issues" 28 | }, 29 | "bundleDependencies": false, 30 | "deprecated": false, 31 | "description": "A basic cache for React applications", 32 | "files": [ 33 | "LICENSE", 34 | "README.md", 35 | "index.js", 36 | "cjs/", 37 | "umd/" 38 | ], 39 | "homepage": "https://github.com/facebook/react#readme", 40 | "name": "react-cache", 41 | "peerDependencies": { 42 | "react": "^16.3.0-alpha.1" 43 | }, 44 | "repository": { 45 | "type": "git", 46 | "url": "git+https://github.com/facebook/react.git" 47 | }, 48 | "version": "2.0.0-alpha.1" 49 | } 50 | -------------------------------------------------------------------------------- /src/packages/react-dom/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | function checkDCE() { 4 | /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ 5 | if ( 6 | typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined' || 7 | typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE !== 'function' 8 | ) { 9 | return; 10 | } 11 | if (process.env.NODE_ENV !== 'production') { 12 | // This branch is unreachable because this function is only called 13 | // in production, but the condition is true only in development. 14 | // Therefore if the branch is still here, dead code elimination wasn't 15 | // properly applied. 16 | // Don't change the message. React DevTools relies on it. Also make sure 17 | // this message doesn't occur elsewhere in this function, or it will cause 18 | // a false positive. 19 | throw new Error('^_^'); 20 | } 21 | try { 22 | // Verify that the code above has been dead code eliminated (DCE'd). 23 | __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(checkDCE); 24 | } catch (err) { 25 | // DevTools shouldn't crash React, no matter what. 26 | // We should still report in case we break this code. 27 | console.error(err); 28 | } 29 | } 30 | 31 | if (process.env.NODE_ENV === 'production') { 32 | // DCE check should happen before ReactDOM bundle executes so that 33 | // DevTools can report bad minification during injection. 34 | checkDCE(); 35 | module.exports = require('./cjs/react-dom.production.min.js'); 36 | } else { 37 | module.exports = require('./cjs/react-dom.development.js'); 38 | } 39 | -------------------------------------------------------------------------------- /src/packages/react-dom/profiling.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | function checkDCE() { 4 | /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ 5 | if ( 6 | typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ === 'undefined' || 7 | typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE !== 'function' 8 | ) { 9 | return; 10 | } 11 | if (process.env.NODE_ENV !== 'production') { 12 | // This branch is unreachable because this function is only called 13 | // in production, but the condition is true only in development. 14 | // Therefore if the branch is still here, dead code elimination wasn't 15 | // properly applied. 16 | // Don't change the message. React DevTools relies on it. Also make sure 17 | // this message doesn't occur elsewhere in this function, or it will cause 18 | // a false positive. 19 | throw new Error('^_^'); 20 | } 21 | try { 22 | // Verify that the code above has been dead code eliminated (DCE'd). 23 | __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(checkDCE); 24 | } catch (err) { 25 | // DevTools shouldn't crash React, no matter what. 26 | // We should still report in case we break this code. 27 | console.error(err); 28 | } 29 | } 30 | 31 | if (process.env.NODE_ENV === 'production') { 32 | // DCE check should happen before ReactDOM bundle executes so that 33 | // DevTools can report bad minification during injection. 34 | checkDCE(); 35 | module.exports = require('./cjs/react-dom.profiling.min.js'); 36 | } else { 37 | module.exports = require('./cjs/react-dom.development.js'); 38 | } 39 | -------------------------------------------------------------------------------- /src/demo/longTaskDemo.tsx: -------------------------------------------------------------------------------- 1 | import React, {useEffect, useRef, useState, useTransition} from 'react'; 2 | import {flushSync} from 'react-dom'; 3 | import {bindHook, utils} from 'log'; 4 | 5 | const {log, lanes2Str, lane2LaneName, COLOR: {SCHEDULE_COLOR, RENDER_COLOR, COMMIT_COLOR}} = utils; 6 | 7 | bindHook('continuationCallback', (root) => { 8 | log(SCHEDULE_COLOR, `continuationCallback`); 9 | }) 10 | bindHook('priorityNotChange', (priority) => { 11 | log(SCHEDULE_COLOR, 'priority没变化,继续原callback', priority); 12 | }) 13 | 14 | bindHook('ensureRootIsScheduled', (lanes, lane) => { 15 | log(SCHEDULE_COLOR, `调度root,lanes:${lanes2Str(lanes)}`, `优先级:${lane2LaneName(lane)}`); 16 | }) 17 | 18 | bindHook('scheduleCallback', (type, cbName, lane) => { 19 | log(SCHEDULE_COLOR, `调度新callback,类型:${type},回调:`, cbName); 20 | }) 21 | 22 | export default function App() { 23 | const [count, updateCount] = useState(0); 24 | const btnRef = useRefsome class component {this.state.num}
; 68 | } 69 | } 70 | 71 | function SomeFunctionComponent() { 72 | useLayoutEffect(() => { 73 | return () => console.log('SomeFunctionComponent will unmount'); 74 | }, []) 75 | returnsome function component
; 76 | } 77 | -------------------------------------------------------------------------------- /src/packages/react-dom/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "_from": "react-dom@beta", 3 | "_id": "react-dom@18.0.0-beta-96ca8d915-20211115", 4 | "_inBundle": false, 5 | "_integrity": "sha512-ISFQGQ0lHt+fz/Ch9K9coggTWzp9ScfuvzdshGJ73z5AI7mi9i6mVjVekMDnx0wiECjHP1s87rxNDQGGj9XnHw==", 6 | "_location": "/react-dom", 7 | "_phantomChildren": {}, 8 | "_requested": { 9 | "type": "tag", 10 | "registry": true, 11 | "raw": "react-dom@beta", 12 | "name": "react-dom", 13 | "escapedName": "react-dom", 14 | "rawSpec": "beta", 15 | "saveSpec": null, 16 | "fetchSpec": "beta" 17 | }, 18 | "_requiredBy": [ 19 | "#USER", 20 | "/" 21 | ], 22 | "_resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.0.0-beta-96ca8d915-20211115.tgz", 23 | "_shasum": "511a754eddbb760c83d85251249fe9c52522326e", 24 | "_spec": "react-dom@beta", 25 | "_where": "/Users/sc/Documents/react18-demo", 26 | "browser": { 27 | "./server.js": "./server.browser.js" 28 | }, 29 | "browserify": { 30 | "transform": [ 31 | "loose-envify" 32 | ] 33 | }, 34 | "bugs": { 35 | "url": "https://github.com/facebook/react/issues" 36 | }, 37 | "bundleDependencies": false, 38 | "dependencies": { 39 | "loose-envify": "^1.1.0", 40 | "object-assign": "^4.1.1", 41 | "scheduler": "0.21.0-beta-96ca8d915-20211115" 42 | }, 43 | "deprecated": false, 44 | "description": "React package for working with the DOM.", 45 | "files": [ 46 | "LICENSE", 47 | "README.md", 48 | "build-info.json", 49 | "index.js", 50 | "profiling.js", 51 | "server.js", 52 | "server.browser.js", 53 | "server.node.js", 54 | "test-utils.js", 55 | "cjs/", 56 | "umd/" 57 | ], 58 | "homepage": "https://reactjs.org/", 59 | "keywords": [ 60 | "react" 61 | ], 62 | "license": "MIT", 63 | "main": "index.js", 64 | "name": "react-dom", 65 | "peerDependencies": { 66 | "react": "18.0.0-beta-96ca8d915-20211115" 67 | }, 68 | "repository": { 69 | "type": "git", 70 | "url": "git+https://github.com/facebook/react.git", 71 | "directory": "packages/react-dom" 72 | }, 73 | "scripts": { 74 | "start": "node server.js" 75 | }, 76 | "version": "18.0.0-beta-96ca8d915-20211115" 77 | } 78 | -------------------------------------------------------------------------------- /src/packages/react-cache/cjs/react-cache.production.min.js: -------------------------------------------------------------------------------- 1 | /** @license React v16.6.0 2 | * react-cache.production.min.js 3 | * 4 | * Copyright (c) Facebook, Inc. and its affiliates. 5 | * 6 | * This source code is licensed under the MIT license found in the 7 | * LICENSE file in the root directory of this source tree. 8 | */ 9 | 10 | 'use strict';Object.defineProperty(exports,"__esModule",{value:!0});var l=require("react"),m=require("scheduler"),n=l.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner;function p(c,e){var f=n.currentDispatcher;if(null===f)throw Error("react-cache: read and preload may only be called from within a component's render. They are not supported in event handlers or lifecycle methods.");return f.readContext(c,e)}function q(c){return c} 11 | var r=function(c){function e(){!1===h&&k>g&&(h=!0,m.unstable_scheduleCallback(f))}function f(){h=!1;var d=g;if(null!==a)for(var b=a.previous;k>d&&null!==b;){var c=b.onDelete,e=b.previous;b.onDelete=null;b.previous=b.next=null;b===a?a=b=null:(a.previous=e,e.next=a,b=e);--k;c()}}var g=c,a=null,k=0,h=!1;return{add:function(d,b){d={value:d,onDelete:b,next:null,previous:null};null===a?d.previous=d.next=d:(b=a.previous,b.next=d,d.previous=b,a.previous=d,d.next=a);a=d;k+=1;return d},update:function(a,b){a.value= 12 | b},access:function(d){var b=d.next;if(null!==b){var c=a;if(a!==d){var f=d.previous;f.next=b;b.previous=f;b=c.previous;b.next=d;d.previous=b;c.previous=d;d.next=c;a=d}}e();return d.value},setLimit:function(a){g=a;e()}}}(500),t=new Map,u=l.createContext(null); 13 | function v(c,e,f,g){var a=t.get(c);void 0===a&&(a=new Map,t.set(c,a));var k=a.get(g);if(void 0===k){e=e(f);e.then(function(a){if(0===h.status){var b=h;b.status=1;b.value=a}},function(a){if(0===h.status){var b=h;b.status=2;b.value=a}});var h={status:0,value:e};c=r.add(h,w.bind(null,c,g));a.set(g,c);return h}return r.access(k)}function w(c,e){var f=t.get(c);void 0!==f&&(f.delete(e),0===f.size&&t.delete(c))} 14 | exports.unstable_createResource=function(c,e){var f=void 0!==e?e:q,g={read:function(a){p(u);var e=f(a);a=v(g,c,a,e);switch(a.status){case 0:throw a.value;case 1:return a.value;case 2:throw a.value;}},preload:function(a){p(u);var e=f(a);v(g,c,a,e)}};return g};exports.unstable_setGlobalCacheLimit=function(c){r.setLimit(c)}; 15 | -------------------------------------------------------------------------------- /src/packages/react/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "_from": "react@beta", 3 | "_id": "react@18.0.0-beta-96ca8d915-20211115", 4 | "_inBundle": false, 5 | "_integrity": "sha512-Io6qvToVSO1UWNWbJSH16gbgYTkseSbfpQvLaB7JPutt0QVvjpUlEE0nfmww77CFdawxGkyfm/x4zvNTlMkHsw==", 6 | "_location": "/react", 7 | "_phantomChildren": {}, 8 | "_requested": { 9 | "type": "tag", 10 | "registry": true, 11 | "raw": "react@beta", 12 | "name": "react", 13 | "escapedName": "react", 14 | "rawSpec": "beta", 15 | "saveSpec": null, 16 | "fetchSpec": "beta" 17 | }, 18 | "_requiredBy": [ 19 | "#USER", 20 | "/" 21 | ], 22 | "_resolved": "https://registry.npmjs.org/react/-/react-18.0.0-beta-96ca8d915-20211115.tgz", 23 | "_shasum": "0b2a0cd808b85fdce987a0c254e0fab979a3828d", 24 | "_spec": "react@beta", 25 | "_where": "/Users/sc/Documents/react18-demo", 26 | "browserify": { 27 | "transform": [ 28 | "loose-envify" 29 | ] 30 | }, 31 | "bugs": { 32 | "url": "https://github.com/facebook/react/issues" 33 | }, 34 | "bundleDependencies": false, 35 | "dependencies": { 36 | "loose-envify": "^1.1.0", 37 | "object-assign": "^4.1.1" 38 | }, 39 | "deprecated": false, 40 | "description": "React is a JavaScript library for building user interfaces.", 41 | "engines": { 42 | "node": ">=0.10.0" 43 | }, 44 | "exports": { 45 | ".": { 46 | "react-server": "./unstable-shared-subset.js", 47 | "default": "./index.js" 48 | }, 49 | "./index": { 50 | "react-server": "./unstable-shared-subset.js", 51 | "default": "./index.js" 52 | }, 53 | "./build-info.json": "./build-info.json", 54 | "./jsx-runtime": "./jsx-runtime.js", 55 | "./jsx-dev-runtime": "./jsx-dev-runtime.js", 56 | "./": "./" 57 | }, 58 | "files": [ 59 | "LICENSE", 60 | "README.md", 61 | "build-info.json", 62 | "index.js", 63 | "cjs/", 64 | "umd/", 65 | "jsx-runtime.js", 66 | "jsx-dev-runtime.js", 67 | "unstable-shared-subset.js" 68 | ], 69 | "homepage": "https://reactjs.org/", 70 | "keywords": [ 71 | "react" 72 | ], 73 | "license": "MIT", 74 | "main": "index.js", 75 | "name": "react", 76 | "repository": { 77 | "type": "git", 78 | "url": "git+https://github.com/facebook/react.git", 79 | "directory": "packages/react" 80 | }, 81 | "version": "18.0.0-beta-96ca8d915-20211115" 82 | } 83 | -------------------------------------------------------------------------------- /src/packages/react-cache/umd/react-cache.production.min.js: -------------------------------------------------------------------------------- 1 | /** @license React v16.6.0 2 | * react-cache.production.min.js 3 | * 4 | * Copyright (c) Facebook, Inc. and its affiliates. 5 | * 6 | * This source code is licensed under the MIT license found in the 7 | * LICENSE file in the root directory of this source tree. 8 | */ 9 | 'use strict';(function(k,m){"object"===typeof exports&&"undefined"!==typeof module?m(exports,require("react"),require("scheduler")):"function"===typeof define&&define.amd?define(["exports","react","scheduler"],m):m(k.ReactCache={},k.React,k.Scheduler)})(this,function(k,m,u){function q(c,e){var f=v.currentDispatcher;if(null===f)throw Error("react-cache: read and preload may only be called from within a component's render. They are not supported in event handlers or lifecycle methods.");return f.readContext(c, 10 | e)}function w(c){return c}function r(c,e,f,g){var a=n.get(c);void 0===a&&(a=new Map,n.set(c,a));var l=a.get(g);if(void 0===l){e=e(f);e.then(function(a){if(0===h.status){var b=h;b.status=1;b.value=a}},function(a){if(0===h.status){var b=h;b.status=2;b.value=a}});var h={status:0,value:e};c=p.add(h,x.bind(null,c,g));a.set(g,c);return h}return p.access(l)}function x(c,e){var f=n.get(c);void 0!==f&&(f.delete(e),0===f.size&&n.delete(c))}var v=m.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, 11 | p=function(c){function e(){!1===h&&l>g&&(h=!0,u.unstable_scheduleCallback(f))}function f(){h=!1;var b=g;if(null!==a)for(var d=a.previous;l>b&&null!==d;){var c=d.onDelete,e=d.previous;d.onDelete=null;d.previous=d.next=null;d===a?a=d=null:(a.previous=e,e.next=a,d=e);--l;c()}}var g=c,a=null,l=0,h=!1;return{add:function(b,d){b={value:b,onDelete:d,next:null,previous:null};null===a?b.previous=b.next=b:(d=a.previous,d.next=b,b.previous=d,a.previous=b,b.next=a);a=b;l+=1;return b},update:function(a,d){a.value= 12 | d},access:function(b){var d=b.next;if(null!==d){var c=a;if(a!==b){var f=b.previous;f.next=d;d.previous=f;d=c.previous;d.next=b;b.previous=d;c.previous=b;b.next=c;a=b}}e();return b.value},setLimit:function(a){g=a;e()}}}(500),n=new Map,t=m.createContext(null);k.unstable_createResource=function(c,e){var f=void 0!==e?e:w,g={read:function(a){q(t);var e=f(a);a=r(g,c,a,e);switch(a.status){case 0:throw a.value;case 1:return a.value;case 2:throw a.value;}},preload:function(a){q(t);var e=f(a);r(g,c,a,e)}}; 13 | return g};k.unstable_setGlobalCacheLimit=function(c){p.setLimit(c)};Object.defineProperty(k,"__esModule",{value:!0})}); 14 | -------------------------------------------------------------------------------- /src/demo/SuspenseDemo/demo2.tsx: -------------------------------------------------------------------------------- 1 | import React, { Suspense } from "react"; 2 | import {bindHook, getLibraryMethod, utils} from 'log'; 3 | import { wrapPromise } from "./utils"; 4 | const {log, lanes2Str, COLOR: {SCHEDULE_COLOR, RENDER_COLOR, COMMIT_COLOR}} = utils; 5 | 6 | bindHook('beginWork', (current, wip) => { 7 | log(RENDER_COLOR, `beginWork`, getLibraryMethod('getComponentNameFromFiber')?.(wip)); 8 | }) 9 | 10 | bindHook('markRootSuspended', (suspendedLanes, rootSuspendedLanes, rootPingedLanes) => { 11 | log(SCHEDULE_COLOR, 'mark Root Suspended', lanes2Str(suspendedLanes)); 12 | }) 13 | bindHook('markRootEntangled', (lanes) => { 14 | log(SCHEDULE_COLOR, 'mark Root Entangled', lanes2Str(lanes)); 15 | }) 16 | 17 | bindHook('attachWakeableListeners', (root, wakeable, lanes) => { 18 | log(RENDER_COLOR, `设置一个ping,优先级为${lanes2Str(lanes)}`, wakeable); 19 | }) 20 | bindHook('markRootPinged', (rootPingedLanes) => { 21 | log(RENDER_COLOR, 'Root Pinged,lanes:', lanes2Str(rootPingedLanes)); 22 | }) 23 | 24 | bindHook('retryTimedOutBoundary', (retryLane) => { 25 | log(RENDER_COLOR, 'Root retry,lane:', lanes2Str(retryLane)); 26 | }) 27 | 28 | bindHook('pushRenderLanes', (fiber, lanes) => { 29 | log(RENDER_COLOR, 'OffscreenComponent push Render Lanes:', lanes2Str(lanes)); 30 | }) 31 | 32 | bindHook('getNextLanes_entangledLanes', (lanes) => { 33 | log(RENDER_COLOR, 'getNextLanes entangledLanes', lanes2Str(lanes)); 34 | }) 35 | 36 | const cache = new Map(); 37 | 38 | function getPicNum(who: string) { 39 | switch (who) { 40 | case "kaSong": 41 | return 230; 42 | case "xiaoMing": 43 | return 122; 44 | default: 45 | return 0; 46 | } 47 | } 48 | 49 | function getTotalPicNum(u1: string, u2: string) { 50 | const cacheKey = `${u1} ${u2}`; 51 | const resourceCache = cache.get(cacheKey); 52 | 53 | if (resourceCache) { 54 | return resourceCache; 55 | } 56 | 57 | const picNumPromise = new Promise((resolve) => { 58 | setTimeout(() => { 59 | resolve(getPicNum(u1) + getPicNum(u2)); 60 | }, 4000); 61 | }); 62 | const resource = wrapPromise(picNumPromise); 63 | cache.set(cacheKey, resource); 64 | return resource; 65 | } 66 | 67 | export default function App() { 68 | return ( 69 |some function component
; 79 | } 80 | 81 | // 事件回调中的错误不会被catch 82 | // const SomeFunctionComponent = () => { 83 | // const handleClick = () => { 84 | // throw new Error("错误发生") 85 | // }; 86 | // return{JSON.stringify({ count, isPending }, null, 2)}
66 | {resource === undefined ? "Initial state" : resource.read()}
67 | a||125d?(a.sortIndex=c,f(t,a),null===h(r)&&a===h(t)&&(B?(E(L),L=-1):B=!0,K(H,c-d))):(a.sortIndex=e,f(r,a),A||z||(A=!0,I(J)));return a};
18 | exports.unstable_shouldYield=M;exports.unstable_wrapCallback=function(a){var b=y;return function(){var c=y;y=b;try{return a.apply(this,arguments)}finally{y=c}}};
19 |
--------------------------------------------------------------------------------
/src/packages/scheduler/cjs/scheduler-unstable_mock.production.min.js:
--------------------------------------------------------------------------------
1 | /** @license React vundefined
2 | * scheduler-unstable_mock.production.min.js
3 | *
4 | * Copyright (c) Facebook, Inc. and its affiliates.
5 | *
6 | * This source code is licensed under the MIT license found in the
7 | * LICENSE file in the root directory of this source tree.
8 | */
9 | 'use strict';function f(a,b){var c=a.length;a.push(b);a:for(;0 >>1,e=a[c];if(0