Skip to content

Conversation

@MagicRB
Copy link
Contributor

@MagicRB MagicRB commented Aug 29, 2025

It turns out that the original code was relying on V8 specific scoping behavior. The value of the argument initialSyncDepth was being set to 1 even when the other arguments inside runBatch were being evaluated and eventually calling runBatch again. So if I were do make a rough trace:

  1. <some function>
  2. call to runBatch with initialSyncDepth set to 1
  3. evaluation of firstBatch argument of runBatch
  4. <some code>
  5. another call to runBatch with no initialSyncDepth set
    ^ here is where the difference manifests, in Firefox the value of initialSyncDepth as seen by the nested call to runBatch will be undefined. However in V8 it will be 1 as the call to runBatch in 2 is still in progress technically.

This difference would lead to desync between the server side and the frontend JS code, which manifests as "spinning" in a tight loop as the frontend is trying to fetch an event that doesn't exist.

Properly fixes #54 and maybe also #64, while also retaining V8 compatibility as far as I can tell.

I tracked this down by running the same JSaddle program in both Firefox and ungoogled-chromium and stepping both in tandem with the respective debuggers until i found a difference.

It turns out that the original code was relying on V8 specific scoping
behavior. The value of the argument `initialSyncDepth` was being set
to `1` even when the other arguments inside `runBatch` were being
evaluated and eventually calling `runBatch` again. So if I were do
make a rough trace:

1. <some function>
2. call to `runBatch` with `initialSyncDepth` set to `1`
3. evaluation of `firstBath` argument of `runBatch`
4. <some code>
5. another call to `runBatch` with no `initialSyncDepth` set
   ^ here is where the difference manifests, in Firefox the value of
   `initialSyncDepth` as seen by the nested call to `runBatch` will be
   `undefined`. However in V8 it will be `1` as the call to `runBatch`
   in 2 is still in progress technically.

This difference would lead to desync between the server side and the
frontend JS code, which manifests as "spinning" in a tight loop as the
frontend is trying to fetch an event that doesn't exist.

Signed-off-by: magic_rb <magic_rb@redalder.org>
@hamishmack hamishmack merged commit 0fb7260 into ghcjs:master Sep 1, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Jsaddle with warp and websockets fails on firefox 57

2 participants