cashapp / cashapp/molecule

`moleculeFlow` with immediate recomposition mode errors on NodeJS

Open
#441 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Kotlin
Stars
2.2k
Forks
116
Avg merge
1h 36m
Merged PRs (30d)
8

Description

I introduced molecule as a way to test some library code which exposes a Composable function. In doing so, I exposed that molecule does not seem to be compatible with NodeJS while running tests. I get the following error:

```
io.github.kevincianfarini.monarch.StateOfTest.stateOf_starts_with_current_value[js, node] FAILED
ReferenceError: window is not defined
at .sendFrame(/home/kevin/code/monarch/compose/build/compileSync/js/test/testDevelopmentExecutable/kotlin/js-ir/runtime/long.kt:27)
at GatedFrameClock.protoOf.set_isRunning_m21k59(/Users/runner/work/molecule/molecule/molecule-runtime/src/commonMain/kotlin/app/cash/molecule/GatedFrameClock.kt:45)
at slambda.protoOf.doResume_5yljmg(/Users/runner/work/molecule/molecule/molecule-runtime/src/commonMain/kotlin/app/cash/molecule/molecule.kt:80)
at slambda.protoOf.invoke_d9fzmj(kotlin/molecule-molecule-runtime.js:459)
at .l(kotlin/molecule-molecule-runtime.js:543)
at .startUndispatchedOrReturn(/home/kevin/code/monarch/compose/build/compileSync/js/test/testDevelopmentExecutable/kotlin/js-ir/src/kotlin/coroutines_13/IntrinsicsJs.kt:99)
at .coroutineScope(/mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/CoroutineScope.kt:261)
at slambda.protoOf.doResume_5yljmg(/Users/runner/work/molecule/molecule/molecule-runtime/src/commonMain/kotlin/app/cash/molecule/molecule.kt:61)
at slambda.protoOf.invoke_ilgcjr(kotlin/molecule-molecule-runtime.js:556)
at SafeFlow.block(kotlin/molecule-molecule-runtime.js:603)
at SafeFlow.protoOf.collectSafely_blptet(/mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/flow/Builders.kt:57)
at 3.protoOf.doResume_5yljmg(/mnt/agent/work/44ec6e850d5c63f0/kotlinx-coroutines-core/common/src/flow/Flow.kt:226)
at SafeFlow.protoOf.collect_aksokr(kotlin/kotlinx-coroutines-core.js:10079)
```

Is this expected behavior? I see that this repository declares JS targets that run tests on the browser, but should that preclude it from running on NodeJS? I've tried using both the Jetbrains Compose plugin while declaring molecule's runtime as `implementation`, and using the molecule plugin directly. Both produce the same results.

Here's a public reproducer sample: https://github.com/kevincianfarini/monarch/commit/b1566e6b1f91bfdfd03b200b6109d0440aff94e7

Contributor guide

No contributing guide indexed for this repository

Research direction

Run the public reproducer and inspect GatedFrameClock.kt around line 45 and molecule.kt around lines 61 and 80, where the NodeJS stack reaches the window reference. Determine which browser assumption breaks immediate recomposition under NodeJS, then verify the reproducer's NodeJS test passes without regressing the browser target.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin, node.js
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.