question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SwitchEventStream breaks parent Signal's lazy-initial-value contract

See original GitHub issue

I found a very strange behavior in my system. For now I have not created a small repro but issue seems very serious so I give you a recap of my trying to narrow down the problem.

    val openSessionRequest = new EventBus[ImportSourceEntry]

    val importFileProcessApiClient1 =
      appCanvas.$clients.value.map(_.map(_.importFileProcessApiClient))

    val importFileProcessApiClient2 =
      appCanvas.$clients.value.map(_.map(_.importFileProcessApiClient))

    val testResult = Val("test1")
      .combineWith(importFileProcessApiClient2)
      .flatMap { t =>
        EventStream.fromValue("test")
      }

… later in code I put some monitoring of what’s going on

              div(
                importFileProcessApiClient --> { client =>
                  error(s"client monitoring mapped val 1 ${client}")
                },
                importFileProcessApiClient2 --> { client =>
                  error(s"client monitoring mapped val 2 ${client}")
                },

appCanvas.$clients is an SignalOptionT from laminext so a thin wrapper around Signal[Option[T]] and it’s value starts with None and then later changes to Some(…)

so importFileProcessApiClient1 and importFileProcessApiClient2 are identical, the only difference is that importFileProcessApiClient2 is used in constructing testResult

what I got is ‘client monitoring mapped val 1 Some(feecompass.app.panel.web.app.AppCanvas$$anon$18@37)’ ‘client monitoring mapped val 2 None’

if I remove the usage of importFileProcessApiClient2 i got what’s expected 'client monitoring direct mapped 1 Some(feecompass.app.panel.web.app.AppCanvas$$anon$18@37) ’ 'client monitoring direct mapped 2 Some(feecompass.app.panel.web.app.AppCanvas$$anon$18@37) ’

if I switch the usage of 1 and 2 the problem appears on 1 'client monitoring mapped val 1 None ’ ‘client monitoring mapped val 2 Some(feecompass.app.panel.web.app.AppCanvas$$anon$18@35)’

Now the strange part testResult is not used anywhere. The trigger for the problem is

      .flatMap({ case (_, _) =>
        EventStream.fromValue("test")
      })

if I comment it out then it works as expected. If testResult is used for instance in div(child <-- testResult.map(t => div(t.toString)), ... the wrong behavior stays the same.

On the other hand switching to FlattenStrategy.ConcurrentStreamStrategy resolves the problem.

It looks as if adding that flatMap with FlattenStrategy.SwitchStreamStrategy messes things up somehow and it’s not related to actual usage of the resulting Observable but just the fact of constructing it. I will let you know if I find something more.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:26 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
pbuszkacommented, Aug 22, 2021

copy paste before I changed to 1 & 2 but to see the diference clearly.

0reactions
raquocommented, Sep 13, 2021

@pbuszka I’ve just released Airstream branch rough-flatten-fix as 0.13.2-RC1. It will be up on Maven Central shortly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

useState lazy initialization and function updates - Kent C. Dodds
So, you call useState with the initial state value, and it returns an array with the value of that state and a mechanism...
Read more >
Lazy initial state - What it is and how to use it? - Stack Overflow
The argument passed to useState is the initialState , the value which initializes your state in the first render and gets disregarded in...
Read more >
Initialize Signals and Discrete States - MATLAB & Simulink
Some systems contain signals and states whose initial values you must specify, for example, the starting position and velocity of a bouncing ball....
Read more >
raquo/Laminar - Issues Antenna
SwitchEventStream breaks parent Signal's lazy -initial-value contract. 000. I found a very strange behavior in my system. For now I have not created...
Read more >
Nikita Gazarov Laminar Issues - Giters
Weird behavior when updating signal while element is unmounted ... SwitchEventStream breaks parent Signal's lazy-initial-value contract.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found