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.

Report duplicate ids in `split` as a warning in dev mode

See original GitHub issue

Howdy!

Even though I understand that the proper usage of split on a Signal[List[_]] expects to have a unique id per element in a list, if you mistakenly have duplicated ids the split bit crashes with an obscure ObserverError: null error.

From that point on, the component starts behaving weirdly, say, if you change the list of items. Also, the stacktrace doesn’t seem to point back to that execution so the error is quite hard to track back to the usage of split and the reason why the error is happening.

Our workaround for now is just to de-duplicate before calling split, however this could be a problem that affects other people. Perhaps doing the same process of deduplication, and/or showing a warning in case there is a duplicated item in the input Signal[List[_]] is a positive change?

Here is a quick snippet to replicate:

import org.scalajs.dom
import com.raquo.laminar.api.L._

// NOTE: There is a duplicated element in this list
val signal = EventStream.empty.toSignal(List(1, 2, 3, 3, 4, 5))

val view: Div = {
  div(
    children <-- signal.split(_.toString) {
      case (id: String, value: Int, valueSignal: Signal[Int]) =>
        div(id)
    }
  )
}

render(
  dom.document.body,
  view
)

https://scalafiddle.io/sf/lq5Urp7/1

JS Cosole log:

VM140:5978 ObserverError: null
com.raquo.airstream.core.Observer$$anon$1.onNext(eval at <anonymous> (https://scalafiddle.io/resultframe?theme=light:46:37), <anonymous>:4513:92)
eval(eval at <anonymous> (https://scalafiddle.io/resultframe?theme=light:46:37), <anonymous>:4540:14)
scala.scalajs.runtime.AnonFunction1.apply(eval at <anonymous> (https://scalafiddle.io/resultframe?theme=light:46:37), <anonymous>:6678:45)
scala.util.Success.fold(eval at <anonymous> (https://scalafiddle.io/resultframe?theme=light:46:37), <anonymous>:9832:17)
com.raquo.airstream.core.Observer$$anon$1.onTry(eval at <anonymous> (https://scalafiddle.io/resultframe?theme=light:46:37), <anonymous>:4536:15)
com.raquo.airstream.signal.Signal.onAddedExternalObserver(eval at <anonymous> (https://scalafiddle.io/resultframe?theme=light:46:37), <anonymous>:4776:12)
com.raquo.airstream.signal.SignalFromEventStream.onAddedExternalObserver(eval at <anonymous> (https://scalafiddle.io/resultframe?theme=light:46:37), <anonymous>:8943:5)
com.raquo.airstream.core.Observable.addObserver(eval at <anonymous> (https://scalafiddle.io/resultframe?theme=light:46:37), <anonymous>:859:9)
com.raquo.airstream.core.Observable.foreach(eval at <anonymous> (https://scalafiddle.io/resultframe?theme=light:46:37), <anonymous>:851:10)
eval(eval at <anonymous> (https://scalafiddle.io/resultframe?theme=light:46:37), <anonymous>:1894:14)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
raquocommented, Sep 29, 2022

The upcoming Airstream 15.0.0 will now detect duplicate keys in split and print warnings to the browser console listing the offending keys as well as the parent observable’s displayName. This is enabled by default to help debugging. To avoid the overhead of checking for duplicates, you might want to disable it either:

a) globally “in production” by setting DuplicateKeysConfig.default.shouldWarn = true in your main App.scala, or

b) for specific large-list splits in your main App.scala by passing the optional duplicateKeys = DuplicateKeysConfig.noWarnings to the split operator (it defaults to DuplicateKeysConfig.default)

For now, the warnings are just that – warnings. They don’t change the behaviour and don’t throw exceptions. This implementation is my initial take to provide some improvement to the dev experience. I might add more advanced configuration in a future version. I’m just not sure what features will be needed yet.

0reactions
raquocommented, Jan 27, 2021

Cool yeah, I think this is what I’ll need, thanks @ngbinh!

Read more comments on GitHub >

github_iconTop Results From Across the Web

GregoryFaust/samblaster - GitHub
samblaster is a fast and flexible program for marking duplicates in read-id grouped 1 paired-end SAM files. It can also optionally output discordant...
Read more >
NetSuite Applications Suite - Duplicate Number Warnings
Setting Company Preferences to Receive Vendor Credit Limit Warnings · Setting Individual Preferences for Vendor Credit Limit Warnings.
Read more >
Determine Duplicate Elements - Rdrr.io
duplicated () determines which elements of a vector or data frame are duplicates of elements with smaller subscripts, and returns a logical vector...
Read more >
DevTools Feature Request: Check for duplicate id attributes in ...
This is a feature request to check for duplicate id attributes on elements, and display a warning in console if duplicates are found....
Read more >
Code Splitting - webpack
Entry Points: Manually split code using entry configuration. Prevent Duplication: Use Entry dependencies or SplitChunksPlugin to dedupe and split chunks.
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