From ae803b80de32a9cd7f625a6a407374e5d7ddb654 Mon Sep 17 00:00:00 2001 From: abdullah1astro Date: Sun, 21 Dec 2025 23:14:49 +0300 Subject: [PATCH] Fix: Prevent uncatchable capability error from DefineFastFlag in client scripts DefineFastFlag requires RobloxScript capability, which client scripts (LocalScripts) do not have. When called from client context, this throws an uncatchable capability error that bypasses pcall/xpcall, causing applications to crash with 'Error occurred, no output from Luau'. Root cause analysis: - Initial debugging attempted React setup fixes (Folder -> ScreenGui, StrictMode restructuring) but the crash persisted - Investigation revealed the issue was in library code attempting DefineFastFlag in a client context - Capability errors cannot be caught by pcall/xpcall in Roblox Solution: - Check script context using RunService before attempting DefineFastFlag - Only call DefineFastFlag in server contexts where capability exists - Client scripts use the safe default (true) without attempting the call - Preserves FastFlag functionality on server while preventing client crashes Benefits: - Eliminates uncatchable capability errors in all client contexts - Maintains FastFlag functionality for server-side A/B testing - Uses safe default (enables memory leak fix) in all contexts - Backward compatible with existing server behavior This fixes crashes affecting all client-side React-Roblox applications using roblox-ts or Luau React directly. Testing: - Verified with roblox-ts React application in client context - Confirmed proper rendering with createRoot and ScreenGui - No errors in client or server contexts --- .../client/roblox/RobloxComponentProps.lua | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/modules/react-roblox/src/client/roblox/RobloxComponentProps.lua b/modules/react-roblox/src/client/roblox/RobloxComponentProps.lua index 0125af02..06e52b87 100644 --- a/modules/react-roblox/src/client/roblox/RobloxComponentProps.lua +++ b/modules/react-roblox/src/client/roblox/RobloxComponentProps.lua @@ -309,11 +309,31 @@ local function updateProperties( end end -local _, FFlagReactFixBindingMemoryLeak = xpcall(function() - return game:DefineFastFlag("ReactFixBindingMemoryLeak", false) -end, function() - return true -end) +-- ============================================================================ +-- FASTFLAG INITIALIZATION WITH CONTEXT DETECTION +-- DefineFastFlag requires RobloxScript capability (server-side only) +-- Client scripts lack this capability and will throw un-catchable errors +-- Sol-> Check context first, only call DefineFastFlag in server contexts +-- ============================================================================ + +local FFlagReactFixBindingMemoryLeak = true -- Safe default for all contexts + +-- Only attempt to DefineFastFlag in server contexts where the capability exists +local RunService = game:GetService("RunService") +local isServerContext = RunService:IsServer() and not RunService:IsClient() + +if isServerContext then + -- Were in a server context safely attempt to get the FastFlag + local success, result = pcall(function() + return game:DefineFastFlag("ReactFixBindingMemoryLeak", false) + end) + + if success and typeof(result) == "boolean" then + FFlagReactFixBindingMemoryLeak = result + end + -- if pcall fails we keep the safe default (true) +end +-- ^^^^^^ Note -> Client scripts always use true (the safe default with memory leak fix enabled) local function cleanupBindings(domElement: HostInstance) local instanceBindings = instanceToBindings[domElement]