O
OneJS15mo ago
amorphous

Cyclical dependency when upgrading to 1.6

Another question as I try to figure out why I can't update to 1.6: is updateHookState from within useReducer in preact/hooks new? It's telling me that is where the cyclical dependency is coming from but I am unsure of how to debug this, especially since all the code before the update was minified.
28 Replies
amorphous
amorphousOP15mo ago
(threading to avoid cluttering main channel - I reckon it might take a bit of work to get things operational.)
amorphous
amorphousOP15mo ago
So it looks like most of the actual UI logic in my game has transitioned over ok, and what's breaking is my JS-side state management. I've been using https://hookstate.js.org/ to handle global state for the UI, and it's pretty deeply embedded into this game to the point that I'm reluctant to swap it with something else (and either way, I'd want some JS-side state management anyway). Using Hookstate with 1.5 and modifying preact/compat so that it was the same version shipped with preact worked well; this is not working for me in 1.6 with the cyclical dependency issue. The error is showing up in the updateHookState function from within preact itself (the version in OneJS, at least), but I've no further leads right now. I can confirm that Hookstate is the problem since removing it and displaying UI elements directly works fine.
Hookstate: supercharged React.useState hook | Hookstate
The most straightforward, extensible and incredibly fast state management that is based on React state hook
amorphous
amorphousOP15mo ago
@Singtaa apologies for ping [it's to add you to the thread], but do you have any insights or suggestions for debugging further with this? Have you worked with cyclical dependency errors before, or have any tips for dealing with them?
Singtaa
Singtaa15mo ago
No worries. Usually the cyclic error stems from JS/Jint trying to serialize a C# object. These can happen from things like == comparison or JSON.stringify(). Generally I'd first start with a git bisect https://git-scm.com/docs/git-bisect to isolate the commit that broke things for you
amorphous
amorphousOP15mo ago
How would we bisect in this case? There's the OneJS repository and the ScriptLib repository -- are there versions that are supposed to work with each other? Since it looks like the JS code is the one that's running foul.
Singtaa
Singtaa15mo ago
Make sure everytime you test a new commit, you are deleting the ScriptLib folder as well Yes most likely it's because of JS-side stuff, but it could also be Jint. You don't need to worry about the ScriptLib repo for the git bisect since it's always included in the main OneJS repo as a gzip file (Once you get the offending commit from the onejs repo, we can deduce the corresponding commit from ScriptLib.) Also see if you can repro the cyclic error in a minimal test code that I can take a look on my side
amorphous
amorphousOP15mo ago
This is the commit where the cyclical dependency issue first started showing up: https://github.com/CreepGin/OneJS/commit/ed9a7ff6f2225d479ddb00eb7029f0e61894c736 I'm going to spend some time this afternoon making a minimal repro. I've a private repository for the minimal repo (private to avoid exposing OneJS) - which Github account should I give access to for it?
Singtaa
Singtaa15mo ago
CreepGin Got it can you set the OneJS submodule to beyond the preact update? (I'm also terrible with submodules)
amorphous
amorphousOP15mo ago
Should be doable by going into the submodule folder (Assets/OneJS) and running git checkout <commit number> in there, I think? If you need a new commit on my end, give me a bit.
Singtaa
Singtaa15mo ago
Ah okay, I think I got it Btw, did you test the latest OneJS repo?
amorphous
amorphousOP15mo ago
yes. err, by 'latest' I'm assuming you mean the 'main' branch
Singtaa
Singtaa15mo ago
yes Hmm I'm not seeing the cyclic error yet
amorphous
amorphousOP15mo ago
Did you run node build when changing the OneJS version?
Singtaa
Singtaa15mo ago
the counter seems to be increasing fine oh let me try that
amorphous
amorphousOP15mo ago
I modified the tsconfig and so it doesn't auto build on file change unless node build -w is running (there's some gotchas in the README in the OneJS folder)
Singtaa
Singtaa15mo ago
Okay, a direct fix is to modify index.js line 1152 to
const allHooksEmpty = stateHooks.every((x) => x._nextValue !== null);
const allHooksEmpty = stateHooks.every((x) => x._nextValue !== null);
amorphous
amorphousOP15mo ago
What's the original 'unfixed' form of the line?
Singtaa
Singtaa15mo ago
!x._nextValue basically the !x._nextValue is triggering the cyclic error and x._nextValue !== null is the workaround Is this something you can modify? Or is it being auto generated by something else?
amorphous
amorphousOP15mo ago
Ah, okay. Looks like that line originally came from ScriptLib/3rdparty/preact/hooks/index.ts on line 238.
Singtaa
Singtaa15mo ago
ah good, then I can just change that upstream
amorphous
amorphousOP15mo ago
I'm very curious why that would cause a cyclic error, if you're willing to elaborate a bit on how you found this.
Singtaa
Singtaa15mo ago
The original preact source code is littered with just == comparisons which works fine in a pure JS environment. But when it's coupled with Jint (C#-JS interop), Jint will somehow try to serialize/stringify the C# obj (it's by design). When I first encountered this (in trying to get Preact to work with Jint), I almost gave up because of it. It's pretty hard to debug when you don't know about the == vs === subtleties in Jint
amorphous
amorphousOP15mo ago
As in, == vs a stricter === comparison?
Singtaa
Singtaa15mo ago
yes
amorphous
amorphousOP15mo ago
Okay, that makes sense. Thank you!
Singtaa
Singtaa15mo ago
You got it! oh wait I think I got the negate sign wrong there. should be x._nextValue === null for completeness I'll change it to typeof x._nextValue == "undefined" || x._nextValue === null in the ScriptLib repo
amorphous
amorphousOP15mo ago
two equal signs for that first one? oh, I guess a type might not strict equal a string?
Singtaa
Singtaa15mo ago
yea string cmp should be fine
Want results from more Discord servers?
Add your server