Skip to content

Commit 3d36b23

Browse files
jackTabsCodeRoFlection Bot
andauthored
Merge upstream (#37)
* #nojira - Upgrade promise dependencies (#396) * Upgrade promise dependencies * Update rotriever.toml Widen range without explicitly upgrading * Update rotriever.toml Bump version * Update README.md * Switch away from PAT, get rbx-aged-cli from foreman instead of node (#397) * APPFDN-2786 useRef `current` should be non-nilable (#398) * Non-nil * Fix types * Fix deviation comment for useBinding * UIBLOX-803: Fix props type-check for memo and forwardRef (#399) Splits abstract component into two types that can be more specific and allow for type-checking to be complete for props. (Errors when types don't match, errors for missing required props) * Optimize tag application (#401) * CLI-113006 - Makes unmount() synchronous (#403) * Makes unmount() synchronous * Typo * u * Use ResetPropertyToDefault for nil prop setting (#404) * Improve MicroProfiler attribution for React work (#405) * wrapPerformWorkWithCoroutine * error handling * Make it more clear * Fix * fix benchmarks * try to remove * maybe * go crazy * no more * shrugs * empty * 17.0.7 * ROBLOX deviation * performWork can yield * speculative fix * Another try * Add comments * clarify * Expose ReactRoblox.flushSync (#406) * Expose ReactRoblox.flushSync * Update rotriever.toml * Export type Object (#407) * Export type Object * bump version * UISYS-3573 Expose more details from React scheduled to Microprofiler to properly represent scheduler work in Microprofiler (#408) --------- Co-authored-by: RoFlection Bot <roflection-bot@roblox.com>
1 parent e6de2cd commit 3d36b23

File tree

21 files changed

+398
-111
lines changed

21 files changed

+398
-111
lines changed

README.md

Lines changed: 34 additions & 34 deletions
Large diffs are not rendered by default.

foreman.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ rojo = { source = "rojo-rbx/rojo", version = "7.3.0" }
33
selene = { source = "Kampfkarren/selene", version = "0.26.1" }
44
stylua = { source = "JohnnyMorganz/StyLua", version = "=0.15.1" }
55
wally = { github = "UpliftGames/wally", version = "=0.3.2" }
6-
luau-lsp = { github = "johnnymorganz/luau-lsp", version = "=1.23.0"}
6+
luau-lsp = { github = "johnnymorganz/luau-lsp", version = "=1.23.0" }
77
darklua = { github = "seaofvoices/darklua", version = "=0.12.1" }
88
lune = { github = "filiptibell/lune", version = "0.7.11" }

modules/react-debug-tools/src/ReactDebugHooks.luau

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,7 @@ local function useReducer<S, I, A>(
292292
return state, function(action: A) end
293293
-- ROBLOX deviation END
294294
end
295-
-- ROBLOX deviation START: TS models this slightly differently, which is needed to have an initially empty ref and clear the ref, and still typecheck
296-
-- local function useRef<T>(initialValue: T): { current: T }
297-
local function useRef<T>(initialValue: T): { current: T | nil }
298-
-- ROBLOX deviation END
295+
local function useRef<T>(initialValue: T): { current: T }
299296
local hook = nextHook()
300297
local ref = if hook ~= nil then hook.memoizedState else { current = initialValue }
301298
table.insert(

modules/react-devtools-shared/src/__tests__/profilingCache.spec.luau

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ xdescribe("ProfilingCache", function()
198198
React.Fragment,
199199
nil,
200200
children,
201-
React.createElement(MemoizedChild, { duration = 1 })
201+
React.createElement(MemoizedChild, { key = -1, duration = 1 })
202202
)
203203
end
204204
function Child(ref)
@@ -656,7 +656,7 @@ xdescribe("ProfilingCache", function()
656656
React.Fragment,
657657
nil,
658658
children,
659-
React.createElement(MemoizedChild, { duration = 1 })
659+
React.createElement(MemoizedChild, { key = -1, duration = 1 })
660660
)
661661
end
662662
function Child(ref)
@@ -759,7 +759,7 @@ xdescribe("ProfilingCache", function()
759759
React.Fragment,
760760
nil,
761761
children,
762-
React.createElement(MemoizedChild, { duration = 1 })
762+
React.createElement(MemoizedChild, { key = -1, duration = 1 })
763763
)
764764
end
765765
function Child(ref)

modules/react-reconciler/src/ReactFiberHooks.new.luau

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,14 +1248,12 @@ function mountBinding<T>(initialValue: T): (ReactBinding<T>, ReactBindingUpdater
12481248
return value, updateValue
12491249
end
12501250

1251-
-- ROBLOX deviation: TS models this slightly differently, which is needed to have an initially empty ref and clear the ref, and still typecheck
12521251
function updateBinding<T>(initialValue: T): (ReactBinding<T>, ReactBindingUpdater<T>)
12531252
local hook = updateWorkInProgressHook()
12541253
return unpack(hook.memoizedState)
12551254
end
12561255

1257-
-- ROBLOX deviation: TS models this slightly differently, which is needed to have an initially empty ref and clear the ref, and still typecheck
1258-
function mountRef<T>(initialValue: T): { current: T | nil }
1256+
function mountRef<T>(initialValue: T): { current: T }
12591257
local hook = mountWorkInProgressHook()
12601258
-- ROBLOX DEVIATION: Implement useRef with bindings
12611259
local ref: any = createRef()
@@ -1264,11 +1262,10 @@ function mountRef<T>(initialValue: T): { current: T | nil }
12641262
-- Object.seal(ref)
12651263
-- end
12661264
hook.memoizedState = ref
1267-
return ref :: { current: T | nil }
1265+
return ref
12681266
end
12691267

1270-
-- ROBLOX deviation: TS models this slightly differently, which is needed to have an initially empty ref and clear the ref, and still typecheck
1271-
function updateRef<T>(initialValue: T): { current: T | nil }
1268+
function updateRef<T>(initialValue: T): { current: T }
12721269
local hook = updateWorkInProgressHook()
12731270
return hook.memoizedState
12741271
end
@@ -2102,8 +2099,7 @@ if __DEV__ then
21022099
-- deviation: Lua version of useState and useReducer return two items, not list like upstream
21032100
return result, setResult
21042101
end,
2105-
-- ROBLOX deviation: TS models this slightly differently, which is needed to have an initially empty ref and clear the ref, and still typecheck
2106-
useRef = function<T>(initialValue: T): { current: T | nil }
2102+
useRef = function<T>(initialValue: T): { current: T }
21072103
currentHookNameInDev = "useRef"
21082104
mountHookTypesDev()
21092105
return mountRef(initialValue)
@@ -2244,8 +2240,7 @@ if __DEV__ then
22442240
-- deviation: Lua version of useState and useReducer return two items, not list like upstream
22452241
return result, setResult
22462242
end,
2247-
-- ROBLOX deviation: TS models this slightly differently, which is needed to have an initially empty ref and clear the ref, and still typecheck
2248-
useRef = function<T>(initialValue: T): { current: T | nil }
2243+
useRef = function<T>(initialValue: T): { current: T }
22492244
currentHookNameInDev = "useRef"
22502245
updateHookTypesDev()
22512246
return mountRef(initialValue)
@@ -2385,8 +2380,7 @@ if __DEV__ then
23852380
-- deviation: Lua version of useState and useReducer return two items, not list like upstream
23862381
return result, setResult
23872382
end,
2388-
-- ROBLOX deviation: TS models this slightly differently, which is needed to have an initially empty ref and clear the ref, and still typecheck
2389-
useRef = function<T>(initialValue: T): { current: T | nil }
2383+
useRef = function<T>(initialValue: T): { current: T }
23902384
currentHookNameInDev = "useRef"
23912385
updateHookTypesDev()
23922386
return updateRef(initialValue)
@@ -2527,8 +2521,7 @@ if __DEV__ then
25272521
-- ROBLOX deviation: Lua version of useState and useReducer return two items, not list like upstream
25282522
return result, setResult
25292523
end,
2530-
-- ROBLOX deviation: TS models this slightly differently, which is needed to have an initially empty ref and clear the ref, and still typecheck
2531-
useRef = function<T>(initialValue: T): { current: T | nil }
2524+
useRef = function<T>(initialValue: T): { current: T }
25322525
currentHookNameInDev = "useRef"
25332526
updateHookTypesDev()
25342527
return updateRef(initialValue)
@@ -2676,8 +2669,7 @@ if __DEV__ then
26762669
-- deviation: Lua version of useState and useReducer return two items, not list like upstream
26772670
return result, setResult
26782671
end,
2679-
-- ROBLOX deviation: TS models this slightly differently, which is needed to have an initially empty ref and clear the ref, and still typecheck
2680-
useRef = function<T>(initialValue: T): { current: T | nil }
2672+
useRef = function<T>(initialValue: T): { current: T }
26812673
currentHookNameInDev = "useRef"
26822674
warnInvalidHookAccess()
26832675
mountHookTypesDev()
@@ -2834,8 +2826,7 @@ if __DEV__ then
28342826
-- deviation: Lua version of useState and useReducer return two items, not list like upstream
28352827
return result, setResult
28362828
end,
2837-
-- ROBLOX deviation: TS models this slightly differently, which is needed to have an initially empty ref and clear the ref, and still typecheck
2838-
useRef = function<T>(initialValue: T): { current: T | nil }
2829+
useRef = function<T>(initialValue: T): { current: T }
28392830
currentHookNameInDev = "useRef"
28402831
warnInvalidHookAccess()
28412832
updateHookTypesDev()
@@ -2992,8 +2983,7 @@ if __DEV__ then
29922983
-- deviation: Lua version of useState and useReducer return two items, not list like upstream
29932984
return result, setResult
29942985
end,
2995-
-- ROBLOX deviation: TS models this slightly differently, which is needed to have an initially empty ref and clear the ref, and still typecheck
2996-
useRef = function<T>(initialValue: T): { current: T | nil }
2986+
useRef = function<T>(initialValue: T): { current: T }
29972987
currentHookNameInDev = "useRef"
29982988
warnInvalidHookAccess()
29992989
updateHookTypesDev()

modules/react-reconciler/src/ReactFiberReconciler.new.luau

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,4 +821,6 @@ exports.injectIntoDevTools = function(devToolsConfig: DevToolsConfig): boolean
821821
})
822822
end
823823

824+
exports.robloxReactProfiling = require(script.Parent.RobloxReactProfiling)
825+
824826
return exports

modules/react-reconciler/src/ReactFiberWorkLoop.new.luau

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ local enqueueUpdate = require("./ReactUpdateQueue.new.lua").enqueueUpdate
220220
local resetContextDependencies =
221221
require("./ReactFiberNewContext.new.lua").resetContextDependencies
222222

223+
-- ROBLOX deviation: RobloxReactProfiling
224+
local RobloxReactProfiling = require(script.Parent.RobloxReactProfiling)
225+
223226
-- ROBLOX deviation: Pre-declare function
224227
local ensureRootIsScheduled
225228

@@ -820,17 +823,29 @@ ensureRootIsScheduled = function(root: FiberRoot, currentTime: number)
820823
-- Special case: Sync React callbacks are scheduled on a special
821824
-- internal queue
822825
newCallbackNode = scheduleSyncCallback(function()
823-
return mod.performSyncWorkOnRoot(root)
826+
-- ROBLOX deviation: RobloxReactProfiling
827+
local profileRunning = RobloxReactProfiling.profileRootBeforeUnitOfWork(root)
828+
local ret = mod.performSyncWorkOnRoot(root)
829+
RobloxReactProfiling.profileRootAfterYielding(profileRunning)
830+
return ret
824831
end)
825832
elseif newCallbackPriority == ReactFiberLane.SyncBatchedLanePriority then
826833
newCallbackNode = scheduleCallback(ImmediateSchedulerPriority, function()
827-
return mod.performSyncWorkOnRoot(root)
834+
-- ROBLOX deviation: RobloxReactProfiling
835+
local profileRunning = RobloxReactProfiling.profileRootBeforeUnitOfWork(root)
836+
local ret = mod.performSyncWorkOnRoot(root)
837+
RobloxReactProfiling.profileRootAfterYielding(profileRunning)
838+
return ret
828839
end)
829840
else
830841
local schedulerPriorityLevel =
831842
lanePriorityToSchedulerPriority(newCallbackPriority)
832843
newCallbackNode = scheduleCallback(schedulerPriorityLevel, function()
833-
return mod.performConcurrentWorkOnRoot(root)
844+
-- ROBLOX deviation: RobloxReactProfiling
845+
local profileRunning = RobloxReactProfiling.profileRootBeforeUnitOfWork(root)
846+
local ret = mod.performConcurrentWorkOnRoot(root)
847+
RobloxReactProfiling.profileRootAfterYielding(profileRunning)
848+
return ret
834849
end)
835850
end
836851

@@ -1923,6 +1938,9 @@ mod.workLoopConcurrent = function()
19231938
end
19241939

19251940
mod.performUnitOfWork = function(unitOfWork: Fiber): ()
1941+
-- ROBLOX deviation: RobloxReactProfiling
1942+
local profileRunning = RobloxReactProfiling.profileUnitOfWorkBefore(unitOfWork)
1943+
19261944
-- The current, flushed, state of this fiber is the alternate. Ideally
19271945
-- nothing should rely on this, but relying on it here means that we don't
19281946
-- need an additional field on the work in progress.
@@ -1952,6 +1970,9 @@ mod.performUnitOfWork = function(unitOfWork: Fiber): ()
19521970
end
19531971

19541972
ReactCurrentOwner.current = nil
1973+
1974+
-- ROBLOX deviation: RobloxReactProfiling
1975+
RobloxReactProfiling.profileUnitOfWorkAfter(profileRunning)
19551976
end
19561977

19571978
mod.completeUnitOfWork = function(unitOfWork: Fiber)
@@ -2065,7 +2086,11 @@ end
20652086
mod.commitRoot = function(root)
20662087
local renderPriorityLevel = getCurrentPriorityLevel()
20672088
runWithPriority(ImmediateSchedulerPriority, function()
2068-
return mod.commitRootImpl(root, renderPriorityLevel)
2089+
-- ROBLOX deviation: RobloxReactProfiling
2090+
RobloxReactProfiling.profileCommitBefore()
2091+
local ret = mod.commitRootImpl(root, renderPriorityLevel)
2092+
RobloxReactProfiling.profileCommitAfter()
2093+
return ret
20692094
end)
20702095
return nil
20712096
end

0 commit comments

Comments
 (0)