[front-end] generate error or warning or info for undefined view model elements

Does anybody know of a way to automatically generate front-end errors or at least some sort of warning if elements likeDivActionsForSelectedPlace are undefined in the frozen state?


If ClientIDs is undefined, of course it crashes but if it has value but does not contain DivActionsForSelectedPlace, it is silently ignored which is bad and needs treatment on each and every case.

also worthy of mention:
If accidentally I try to assign to / change a value in the frozen state by accident/unaware, it is silently ignored. Any idea on how to guard against this and somehow generate a message to Console tab? (The online docs warn about this and this is a good thing)

1 Like

Yea, this just returns undefined in javascript, I’d probably make a helper function for finding elements by id

function ensureElement(id) {
    const element = document.getElementById(id)
    if (!element) throw new Error(`Didn't find element ${id}`)
    return element

Or,you can declarefunction fail(msg) { throw new Error(msg) }, then the error handling at least simplifies to state.Ids.Whatever ?? fail('missing id')

Yes, use JS strict mode.

"use strict"
let x = Object.freeze({a:1})
x.a = 10 // throws error
1 Like

LE: So, it works in InlineScript control with your example. But it doesn’t with the dotvvm state.


I thought that dotvvm.state is already frozen. Puzzled.

dotvvm.state.OnClientComebackNullifyPopup = false also goes along silently.


Looks like I have to do this

And it fails in Console tab as I desired:

Oh shit, turns out we are not actually freezing the view model :man_facepalming: Thanks for helping us find out!

1 Like

sure, no prob

Please give me an update on this thread when a fix is launched, so I can reverse the “Object.freeze” extras.

We have fixed the Object.freeze bug in the 4.3.0-preview03-final version. We cannot release this as a 4.2 patch, since it could break someone. Version 4.3 should be compatible with 4.2 BP, bootstrap and other components (I hope they didn’t depend on the objects not being freezed :sweat_smile:)

1 Like

How do I install this 4.3.0-preview03-final ?

I’d just replace <PackageReference Include="DotVVM" Version="4.2.6" /> with <PackageReference Include="DotVVM" Version="4.3.0-preview03-final" />, but you should be able to install it with the Visual Studio NuGet GUI

No worries, sorry. I forgot to check “Include prerelease”

1 Like