Warn if ChildNode is used as modifier multiple times. #183
Replies: 2 comments 1 reply
-
Yep, our elements are real, not virtual. That's the expected tradeoff. But yeah, I think we can add such warnings. I think, perhaps they could be warnings-only, so they would not throw an error, just inform the user of the issue via the browser console. Similar to the duplicate key warnings that we already have. Actually, the warnings you propose could theoretically replace the duplicate key warnings, except they probably wouldn't provide enough details. But, they're cheaper. Anyway. This issue you brought up is related to moving elements, and we have a bunch of tasks in this general area shaping up in #163 – I will need to find a good place to integrate these warnings, and to provide a way to opt-out of them, where moving the element is intentional – perhaps using the same |
Beta Was this translation helpful? Give feedback.
-
I made this an issue, since it's directly actionable, for better visibility, so I'm closing the discussion here. See |
Beta Was this translation helpful? Give feedback.
-
Recently, I've encountered an issue with some elements being not displayed where expected.
Here's a simplified and minimized example to demonstrate my case:
See https://scastie.scala-lang.org/8dB25QZfRtW0ZuamN4x88w
The root case traces back to a lack of referential transparency: an expression of the node declaration can't be assigned to a
val
and reused. That's because there is an allocation side-effect, which is probably fine to have as Laminar don't pretend to be FP framework. With mixed feelings, I've completely fixed my particular problem by simply changingval
definition todef
.If I understand correctly, using an element as a modifier is equivalent to setting a parent, and the most common case is when there were no parent before.
Given the above, I think maybe it would make sense to have a warning when element is used as modifier while the parent is already set. In case when changing the parent was intentional, maybe it's better to have an explicit mechanism (e.g. method, function, event) for that, rather than using modifier syntax?
Beta Was this translation helpful? Give feedback.
All reactions