You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When defining a local F# function in a Fable project with a name that matches a global JavaScript function (e.g., setTimeout, clearTimeout), Fable always references the local function, even in contexts where the global JavaScript function is intended to be used. This behavior can lead to unexpected errors, such as "RangeError: Maximum call stack size exceeded", due to recursive calls when the local function tries to use the global one indirectly.
Repro code:
moduleClient.TestopenFeliz[<ReactComponent>]letMyComponent()=lettimeoutRef= React.useRef None
// This local function unintentionally shadows the global JS clearTimeout functionletclearTimeout()=
timeoutRef.current
|> Option.iter Fable.Core.JS.clearTimeout // Intended to use global clearTimeoutletstartTimeout()=
timeoutRef.current <- Some (Fable.Core.JS.setTimeout (fun()-> printfn "Hello")3000)
Html.div [
Html.button [
prop.className "px-3 py-2 border"
prop.onClick (fun _ -> startTimeout ())
prop.text "Start timeout"]
Html.button [
prop.className "px-3 py-2 border"
prop.onClick (fun _ -> clearTimeout ())
prop.text "Clear timeout"]]
Expected and actual results:
Expected: The clearTimeout call within the local clearTimeout function should reference the global JavaScript clearTimeout function, allowing for the proper clearing of timeouts set with setTimeout.
Actual: The local clearTimeout function is recursively calling itself instead of the global JavaScript clearTimeout, leading to a "RangeError: Maximum call stack size exceeded" error.
It might be beneficial for Fable to provide clearer warnings or errors during compilation when local function names shadow global JavaScript functions, or potentially offer a way to explicitly reference global functions in such cases.
Related information:
Fable version: 4.14.0
Operating system: MacOS Sonoma
The text was updated successfully, but these errors were encountered:
Description:
When defining a local F# function in a Fable project with a name that matches a global JavaScript function (e.g.,
setTimeout
,clearTimeout
), Fable always references the local function, even in contexts where the global JavaScript function is intended to be used. This behavior can lead to unexpected errors, such as "RangeError: Maximum call stack size exceeded", due to recursive calls when the local function tries to use the global one indirectly.Repro code:
Expected and actual results:
Expected: The
clearTimeout
call within the localclearTimeout
function should reference the global JavaScriptclearTimeout
function, allowing for the proper clearing of timeouts set withsetTimeout
.Actual: The local
clearTimeout
function is recursively calling itself instead of the global JavaScriptclearTimeout
, leading to a "RangeError: Maximum call stack size exceeded" error.Suggested Solution:
It might be beneficial for Fable to provide clearer warnings or errors during compilation when local function names shadow global JavaScript functions, or potentially offer a way to explicitly reference global functions in such cases.
Related information:
The text was updated successfully, but these errors were encountered: