Fable Nagareyama - issue with structuralHash leads to rendering failure in Feliz.Plotly

Created on 1 Dec 2020  路  8Comments  路  Source: fable-compiler/Fable

Description

A change made to fable-library/Util.ts/structuralHash in Fable 3 seems to be breaking view rendering for Feliz.Plotly plots.
Before the upgrade, plots were working as expected.

Repro code

The error I am getting is:

Util.js?6576:205 Uncaught RangeError: Maximum call stack size exceeded
    at Function.values (<anonymous>)
    at structuralHash (Util.js?6576:205)
    at eval (Util.js?6576:205)
    at Array.map (<anonymous>)

The stack trace doesn't lead to any of my code, there's just a bit under 200 repetitive calls of eval and structuralHash from Util.js, which eventually lead to that 'call stack size exceeded' error.
The line of code in Util.js where the failure is happening has a comment that might be helpful:

 // TODO: check call-stack to prevernt cyclic objects?
const hashes = Object.values(self).map((v) => structuralHash(v));

Right after the error above, the following error comes:

The above error occurred in the <Components_LazyView$1> component:
    in Components_LazyView$1

Consider adding an error boundary to your tree to customize error handling behavior.
Visit https://fb.me/react-error-boundaries to learn more about error boundaries

Expected and actual results

Expected: Feliz.Plotly plots are rendered without errors.
Actual: rendering is failing and the whole page disappears. The error quoted above appears in console.

Related information

  • Fable version: 3.0.0-nagareyama-rc-005
  • Operating system: Windows 10

Most helpful comment

@Shmew The issue is no longer happening after I updated Fable to rc10. The problem was that computing structuralHash for some internal object involved in Feliz.Plotly rendering was leading to an infinite recursion and failing eventually when call stack was exceeded. Unfortunately, stack trace wasn't really showing which object the error was happening for.

All 8 comments

@Shmew Here is the issue for that problem I described in Fable gitter :)

Sorry for that! There was another issue with hashing that should be fixed in RC9. Could you please try upgrading Fable (dotnet tool update fable --version "3.0.0-*") and check if this fixes the issue?

@alfonsogarciacaro Upgraded Fable to rc10, and the issue is no longer appearing! Thank you for the quick help :)

Great, thanks for confirming! Although now that I read your message more carefully, it may still be possible to fall in that trap in some situations, it may need to be fixed.

Is there anything I can do from my side of things to help prevent this? What was the root cause?

@alfonsogarciacaro Should I keep this issue open for now? Or would be better to create a new one that is not specific to Feliz.Plotly?

@Shmew The issue is no longer happening after I updated Fable to rc10. The problem was that computing structuralHash for some internal object involved in Feliz.Plotly rendering was leading to an infinite recursion and failing eventually when call stack was exceeded. Unfortunately, stack trace wasn't really showing which object the error was happening for.

It's tricky, if it was actually the same thing as #2291 the problem was that Fable 3 was using structural hashing instead of identity hashing for classes. This should be fixed now. The potential issue witch structural hashing and cyclic objects persists but I'm not sure how/if we should fix it. This seems to crash F# interactive too:

type R1 = { mutable R2: R2 }
and R2 = { mutable R1: R1 }

let r1 = { R2 = Unchecked.defaultof<R2> }
let r2 = { R1 = Unchecked.defaultof<R1> }
r1.R2 <- r2
r2.R1 <- r1
hash r1

So let's close the issue for now and wait until it blows somewhere else 馃檲

Was this page helpful?
0 / 5 - 0 ratings