scheduler
Advanced tools
Comparing version 0.0.0-experimental-e7d0053e6-20220325 to 0.0.0-experimental-e7d213dfb0-20240507
@@ -5,3 +5,3 @@ /** | ||
* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
@@ -207,15 +207,3 @@ * This source code is licensed under the MIT license found in the | ||
try { | ||
if (enableProfiling) { | ||
try { | ||
return workLoop(hasTimeRemaining, initialTime); | ||
} catch (error) { | ||
if (currentTask !== null) { | ||
var currentTime = getCurrentTime(); | ||
markTaskErrored(currentTask, currentTime); | ||
currentTask.isQueued = false; | ||
} | ||
throw error; | ||
} | ||
} else { | ||
var currentTime; if (enableProfiling) ; else { | ||
// No catch in prod code path. | ||
@@ -240,9 +228,13 @@ return workLoop(hasTimeRemaining, initialTime); | ||
break; | ||
} | ||
} // $FlowFixMe[incompatible-use] found when upgrading Flow | ||
var callback = currentTask.callback; | ||
if (typeof callback === 'function') { | ||
currentTask.callback = null; | ||
currentPriorityLevel = currentTask.priorityLevel; | ||
// $FlowFixMe[incompatible-use] found when upgrading Flow | ||
currentTask.callback = null; // $FlowFixMe[incompatible-use] found when upgrading Flow | ||
currentPriorityLevel = currentTask.priorityLevel; // $FlowFixMe[incompatible-use] found when upgrading Flow | ||
var didUserCallbackTimeout = currentTask.expirationTime <= currentTime; | ||
@@ -254,3 +246,13 @@ | ||
if (typeof continuationCallback === 'function') { | ||
// If a continuation is returned, immediately yield to the main thread | ||
// regardless of how much time is left in the current time slice. | ||
// $FlowFixMe[incompatible-use] found when upgrading Flow | ||
currentTask.callback = continuationCallback; | ||
advanceTimers(currentTime); | ||
if (shouldYieldForPaint) { | ||
needsPaint = true; | ||
return true; | ||
} | ||
} else { | ||
@@ -261,5 +263,5 @@ | ||
} | ||
advanceTimers(currentTime); | ||
} | ||
advanceTimers(currentTime); | ||
} else { | ||
@@ -337,3 +339,5 @@ pop(taskQueue); | ||
function unstable_wrapCallback(callback) { | ||
var parentPriorityLevel = currentPriorityLevel; | ||
var parentPriorityLevel = currentPriorityLevel; // $FlowFixMe[incompatible-return] | ||
// $FlowFixMe[missing-this-annot] | ||
return function () { | ||
@@ -565,4 +569,10 @@ // This is a fork of runWithPriority, inlined for performance. | ||
} | ||
return false; | ||
} | ||
function unstable_hasPendingWork() { | ||
return scheduledCallback !== null; | ||
} | ||
function unstable_flushExpired() { | ||
@@ -618,3 +628,3 @@ if (isFlushing) { | ||
function unstable_clearYields() { | ||
function unstable_clearLog() { | ||
if (yieldedValues === null) { | ||
@@ -641,3 +651,3 @@ return []; | ||
function unstable_yieldValue(value) { | ||
function log(value) { | ||
// eslint-disable-next-line react-internal/no-production-logging | ||
@@ -677,4 +687,5 @@ if (console.log.name === 'disabledLog' || disableYieldValue) { | ||
} | ||
var unstable_Profiling = null; | ||
var unstable_Profiling = null; | ||
exports.log = log; | ||
exports.reset = reset; | ||
@@ -689,3 +700,3 @@ exports.unstable_IdlePriority = IdlePriority; | ||
exports.unstable_cancelCallback = unstable_cancelCallback; | ||
exports.unstable_clearYields = unstable_clearYields; | ||
exports.unstable_clearLog = unstable_clearLog; | ||
exports.unstable_continueExecution = unstable_continueExecution; | ||
@@ -700,2 +711,3 @@ exports.unstable_flushAll = unstable_flushAll; | ||
exports.unstable_getFirstCallbackNode = unstable_getFirstCallbackNode; | ||
exports.unstable_hasPendingWork = unstable_hasPendingWork; | ||
exports.unstable_next = unstable_next; | ||
@@ -710,4 +722,3 @@ exports.unstable_now = getCurrentTime; | ||
exports.unstable_wrapCallback = unstable_wrapCallback; | ||
exports.unstable_yieldValue = unstable_yieldValue; | ||
})(); | ||
} |
@@ -5,3 +5,3 @@ /** | ||
* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
@@ -37,4 +37,3 @@ * This source code is licensed under the MIT license found in the | ||
var deadline = 0; | ||
var currentPriorityLevel_DEPRECATED = NormalPriority; // `isInputPending` is not available. Since we have no way of knowing if | ||
// there's pending input, always yield at the end of the frame. | ||
var currentPriorityLevel_DEPRECATED = NormalPriority; // Always yield at the end of the frame. | ||
@@ -69,5 +68,6 @@ function unstable_shouldYield() { | ||
var controller = new TaskController(); | ||
var controller = new TaskController({ | ||
priority: postTaskPriority | ||
}); | ||
var postTaskOptions = { | ||
priority: postTaskPriority, | ||
delay: typeof options === 'object' && options !== null ? options.delay : 0, | ||
@@ -88,4 +88,4 @@ signal: controller.signal | ||
currentPriorityLevel_DEPRECATED = priorityLevel; | ||
var _didTimeout_DEPRECATED = false; | ||
var result = callback(_didTimeout_DEPRECATED); | ||
var didTimeout_DEPRECATED = false; | ||
var result = callback(didTimeout_DEPRECATED); | ||
@@ -95,11 +95,12 @@ if (typeof result === 'function') { | ||
var continuation = result; | ||
var continuationController = new TaskController(); | ||
var continuationOptions = { | ||
priority: postTaskPriority, | ||
signal: continuationController.signal | ||
}; // Update the original callback node's controller, since even though we're | ||
// posting a new task, conceptually it's the same one. | ||
signal: node._controller.signal | ||
}; | ||
var nextTask = runTask.bind(null, priorityLevel, postTaskPriority, node, continuation); | ||
node._controller = continuationController; | ||
scheduler.postTask(runTask.bind(null, priorityLevel, postTaskPriority, node, continuation), continuationOptions).catch(handleAbortError); | ||
if (scheduler.yield !== undefined) { | ||
scheduler.yield(continuationOptions).then(nextTask).catch(handleAbortError); | ||
} else { | ||
scheduler.postTask(nextTask, continuationOptions).catch(handleAbortError); | ||
} | ||
} | ||
@@ -106,0 +107,0 @@ } catch (error) { |
@@ -5,3 +5,3 @@ /** | ||
* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
@@ -16,6 +16,3 @@ * This source code is licensed under the MIT license found in the | ||
(function() { | ||
'use strict'; | ||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ | ||
'use strict'; | ||
if ( | ||
@@ -28,5 +25,8 @@ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && | ||
} | ||
var enableSchedulerDebugging = false; | ||
var enableSchedulerDebugging = false; | ||
var enableProfiling = false; | ||
var frameYieldMs = 5; | ||
var userBlockingPriorityTimeout = 250; | ||
var normalPriorityTimeout = 5000; | ||
var lowPriorityTimeout = 10000; | ||
@@ -125,5 +125,6 @@ function push(heap, node) { | ||
/* eslint-disable no-var */ | ||
exports.unstable_now = void 0; | ||
var hasPerformanceNow = // $FlowFixMe[method-unbinding] | ||
typeof performance === 'object' && typeof performance.now === 'function'; | ||
var hasPerformanceNow = typeof performance === 'object' && typeof performance.now === 'function'; | ||
if (hasPerformanceNow) { | ||
@@ -147,12 +148,4 @@ var localPerformance = performance; | ||
var maxSigned31BitInt = 1073741823; // Times out immediately | ||
var maxSigned31BitInt = 1073741823; // Tasks are stored on a min heap | ||
var IMMEDIATE_PRIORITY_TIMEOUT = -1; // Eventually times out | ||
var USER_BLOCKING_PRIORITY_TIMEOUT = 250; | ||
var NORMAL_PRIORITY_TIMEOUT = 5000; | ||
var LOW_PRIORITY_TIMEOUT = 10000; // Never times out | ||
var IDLE_PRIORITY_TIMEOUT = maxSigned31BitInt; // Tasks are stored on a min heap | ||
var taskQueue = []; | ||
@@ -173,4 +166,2 @@ var timerQueue = []; // Incrementing id counter. Used to maintain insertion order. | ||
var isInputPending = typeof navigator !== 'undefined' && navigator.scheduling !== undefined && navigator.scheduling.isInputPending !== undefined ? navigator.scheduling.isInputPending.bind(navigator.scheduling) : null; | ||
function advanceTimers(currentTime) { | ||
@@ -205,3 +196,3 @@ // Check for tasks that are no longer delayed and add them to the queue. | ||
isHostCallbackScheduled = true; | ||
requestHostCallback(flushWork); | ||
requestHostCallback(); | ||
} else { | ||
@@ -217,3 +208,3 @@ var firstTimer = peek(timerQueue); | ||
function flushWork(hasTimeRemaining, initialTime) { | ||
function flushWork(initialTime) { | ||
@@ -233,17 +224,5 @@ | ||
try { | ||
if (enableProfiling) { | ||
try { | ||
return workLoop(hasTimeRemaining, initialTime); | ||
} catch (error) { | ||
if (currentTask !== null) { | ||
var currentTime = exports.unstable_now(); | ||
markTaskErrored(currentTask, currentTime); | ||
currentTask.isQueued = false; | ||
} | ||
throw error; | ||
} | ||
} else { | ||
var currentTime; if (enableProfiling) ; else { | ||
// No catch in prod code path. | ||
return workLoop(hasTimeRemaining, initialTime); | ||
return workLoop(initialTime); | ||
} | ||
@@ -257,3 +236,3 @@ } finally { | ||
function workLoop(hasTimeRemaining, initialTime) { | ||
function workLoop(initialTime) { | ||
var currentTime = initialTime; | ||
@@ -264,12 +243,16 @@ advanceTimers(currentTime); | ||
while (currentTask !== null && !(enableSchedulerDebugging )) { | ||
if (currentTask.expirationTime > currentTime && (!hasTimeRemaining || shouldYieldToHost())) { | ||
if (currentTask.expirationTime > currentTime && shouldYieldToHost()) { | ||
// This currentTask hasn't expired, and we've reached the deadline. | ||
break; | ||
} | ||
} // $FlowFixMe[incompatible-use] found when upgrading Flow | ||
var callback = currentTask.callback; | ||
if (typeof callback === 'function') { | ||
currentTask.callback = null; | ||
currentPriorityLevel = currentTask.priorityLevel; | ||
// $FlowFixMe[incompatible-use] found when upgrading Flow | ||
currentTask.callback = null; // $FlowFixMe[incompatible-use] found when upgrading Flow | ||
currentPriorityLevel = currentTask.priorityLevel; // $FlowFixMe[incompatible-use] found when upgrading Flow | ||
var didUserCallbackTimeout = currentTask.expirationTime <= currentTime; | ||
@@ -281,3 +264,9 @@ | ||
if (typeof continuationCallback === 'function') { | ||
// If a continuation is returned, immediately yield to the main thread | ||
// regardless of how much time is left in the current time slice. | ||
// $FlowFixMe[incompatible-use] found when upgrading Flow | ||
currentTask.callback = continuationCallback; | ||
advanceTimers(currentTime); | ||
return true; | ||
} else { | ||
@@ -288,5 +277,5 @@ | ||
} | ||
advanceTimers(currentTime); | ||
} | ||
advanceTimers(currentTime); | ||
} else { | ||
@@ -364,3 +353,5 @@ pop(taskQueue); | ||
function unstable_wrapCallback(callback) { | ||
var parentPriorityLevel = currentPriorityLevel; | ||
var parentPriorityLevel = currentPriorityLevel; // $FlowFixMe[incompatible-return] | ||
// $FlowFixMe[missing-this-annot] | ||
return function () { | ||
@@ -399,15 +390,19 @@ // This is a fork of runWithPriority, inlined for performance. | ||
case ImmediatePriority: | ||
timeout = IMMEDIATE_PRIORITY_TIMEOUT; | ||
// Times out immediately | ||
timeout = -1; | ||
break; | ||
case UserBlockingPriority: | ||
timeout = USER_BLOCKING_PRIORITY_TIMEOUT; | ||
// Eventually times out | ||
timeout = userBlockingPriorityTimeout; | ||
break; | ||
case IdlePriority: | ||
timeout = IDLE_PRIORITY_TIMEOUT; | ||
// Never times out | ||
timeout = maxSigned31BitInt; | ||
break; | ||
case LowPriority: | ||
timeout = LOW_PRIORITY_TIMEOUT; | ||
// Eventually times out | ||
timeout = lowPriorityTimeout; | ||
break; | ||
@@ -417,3 +412,4 @@ | ||
default: | ||
timeout = NORMAL_PRIORITY_TIMEOUT; | ||
// Eventually times out | ||
timeout = normalPriorityTimeout; | ||
break; | ||
@@ -457,3 +453,3 @@ } | ||
isHostCallbackScheduled = true; | ||
requestHostCallback(flushWork); | ||
requestHostCallback(); | ||
} | ||
@@ -472,3 +468,3 @@ } | ||
isHostCallbackScheduled = true; | ||
requestHostCallback(flushWork); | ||
requestHostCallback(); | ||
} | ||
@@ -494,3 +490,2 @@ } | ||
var isMessageLoopRunning = false; | ||
var scheduledHostCallback = null; | ||
var taskTimeoutID = -1; // Scheduler periodically yields in case there is other work on the main | ||
@@ -511,3 +506,3 @@ // thread, like user events. By default, it yields multiple times per frame. | ||
return false; | ||
} // The main thread has been blocked for a non-negligible amount of time. We | ||
} // Yield now. | ||
@@ -518,6 +513,4 @@ | ||
function requestPaint() { | ||
function requestPaint() {} | ||
} | ||
function forceFrameRate(fps) { | ||
@@ -539,13 +532,12 @@ if (fps < 0 || fps > 125) { | ||
var performWorkUntilDeadline = function () { | ||
if (scheduledHostCallback !== null) { | ||
if (isMessageLoopRunning) { | ||
var currentTime = exports.unstable_now(); // Keep track of the start time so we can measure how long the main thread | ||
// has been blocked. | ||
startTime = currentTime; | ||
var hasTimeRemaining = true; // If a scheduler task throws, exit the current browser task so the | ||
startTime = currentTime; // If a scheduler task throws, exit the current browser task so the | ||
// error can be observed. | ||
// | ||
// Intentionally not using a try-catch, since that makes some debugging | ||
// techniques harder. Instead, if `scheduledHostCallback` errors, then | ||
// `hasMoreWork` will remain true, and we'll continue the work loop. | ||
// techniques harder. Instead, if `flushWork` errors, then `hasMoreWork` will | ||
// remain true, and we'll continue the work loop. | ||
@@ -555,3 +547,3 @@ var hasMoreWork = true; | ||
try { | ||
hasMoreWork = scheduledHostCallback(hasTimeRemaining, currentTime); | ||
hasMoreWork = flushWork(currentTime); | ||
} finally { | ||
@@ -564,8 +556,5 @@ if (hasMoreWork) { | ||
isMessageLoopRunning = false; | ||
scheduledHostCallback = null; | ||
} | ||
} | ||
} else { | ||
isMessageLoopRunning = false; | ||
} // Yielding to the browser will give it a chance to paint, so we can | ||
} | ||
}; | ||
@@ -603,2 +592,3 @@ | ||
schedulePerformWorkUntilDeadline = function () { | ||
// $FlowFixMe[not-a-function] nullable value | ||
localSetTimeout(performWorkUntilDeadline, 0); | ||
@@ -608,5 +598,3 @@ }; | ||
function requestHostCallback(callback) { | ||
scheduledHostCallback = callback; | ||
function requestHostCallback() { | ||
if (!isMessageLoopRunning) { | ||
@@ -619,2 +607,3 @@ isMessageLoopRunning = true; | ||
function requestHostTimeout(callback, ms) { | ||
// $FlowFixMe[not-a-function] nullable value | ||
taskTimeoutID = localSetTimeout(function () { | ||
@@ -626,9 +615,8 @@ callback(exports.unstable_now()); | ||
function cancelHostTimeout() { | ||
// $FlowFixMe[not-a-function] nullable value | ||
localClearTimeout(taskTimeoutID); | ||
taskTimeoutID = -1; | ||
} | ||
var unstable_Profiling = null; | ||
var unstable_requestPaint = requestPaint; | ||
var unstable_Profiling = null; | ||
exports.unstable_IdlePriority = IdlePriority; | ||
@@ -647,3 +635,3 @@ exports.unstable_ImmediatePriority = ImmediatePriority; | ||
exports.unstable_pauseExecution = unstable_pauseExecution; | ||
exports.unstable_requestPaint = unstable_requestPaint; | ||
exports.unstable_requestPaint = requestPaint; | ||
exports.unstable_runWithPriority = unstable_runWithPriority; | ||
@@ -653,3 +641,2 @@ exports.unstable_scheduleCallback = unstable_scheduleCallback; | ||
exports.unstable_wrapCallback = unstable_wrapCallback; | ||
/* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */ | ||
if ( | ||
@@ -662,4 +649,4 @@ typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' && | ||
} | ||
})(); | ||
} |
'use strict'; | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./cjs/scheduler.production.min.js'); | ||
module.exports = require('./cjs/scheduler.production.js'); | ||
} else { | ||
module.exports = require('./cjs/scheduler.development.js'); | ||
} |
{ | ||
"name": "scheduler", | ||
"version": "0.0.0-experimental-e7d0053e6-20220325", | ||
"version": "0.0.0-experimental-e7d213dfb0-20240507", | ||
"description": "Cooperative scheduler for the browser environment.", | ||
"main": "index.js", | ||
"repository": { | ||
@@ -18,6 +17,3 @@ "type": "git", | ||
}, | ||
"homepage": "https://reactjs.org/", | ||
"dependencies": { | ||
"loose-envify": "^1.1.0" | ||
}, | ||
"homepage": "https://react.dev/", | ||
"files": [ | ||
@@ -27,12 +23,7 @@ "LICENSE", | ||
"index.js", | ||
"index.native.js", | ||
"unstable_mock.js", | ||
"unstable_post_task.js", | ||
"cjs/", | ||
"umd/" | ||
], | ||
"browserify": { | ||
"transform": [ | ||
"loose-envify" | ||
] | ||
} | ||
"cjs/" | ||
] | ||
} |
'use strict'; | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./cjs/scheduler-unstable_mock.production.min.js'); | ||
module.exports = require('./cjs/scheduler-unstable_mock.production.js'); | ||
} else { | ||
module.exports = require('./cjs/scheduler-unstable_mock.development.js'); | ||
} |
'use strict'; | ||
if (process.env.NODE_ENV === 'production') { | ||
module.exports = require('./cjs/scheduler-unstable_post_task.production.min.js'); | ||
module.exports = require('./cjs/scheduler-unstable_post_task.production.js'); | ||
} else { | ||
module.exports = require('./cjs/scheduler-unstable_post_task.development.js'); | ||
} |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
99114
0
2950
15
4
1
- Removedloose-envify@^1.1.0
- Removedjs-tokens@4.0.0(transitive)
- Removedloose-envify@1.4.0(transitive)