You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
oh-context variables and constant expressions are evaluated before the component is mounted. If the UI is newly opened (or recently reset) any item states are not available via the store when those expression are calculated for the very first time.
Replicate the issue
Here's a basic widget:
uid: demo-context-errortags: []props:
parameters: []parameterGroups: []timestamp: Oct 27, 2024, 11:04:06 AMcomponent: oh-contextconfig:
constants:
testItemConst: =`testNumber state is ${items.testNumber.state}`variables:
testItemVar: =`testNumber state is ${items.testNumber.state}`slots:
default:
- component: f7-cardconfig:
title: =`testNumber state is ${items.testNumber.state}`content: =const.testItemConstfooter: =vars.testItemVar
All three text outputs should be the same:
However, after a [ctrl + shft + f5] the result is different:
At this point, however, the item is now in the store because of the title expression so any further interaction (refresh the widget, leave the page and come back, etc.) will result in the proper calculations.
Even if you do activities first, for example open some other widgets or pages in the UI, the first time this widget is opened the item states are not properly available.
...except! Here's a second widget:
uid: demo-context-error-2tags: []props:
parameters: []parameterGroups: []timestamp: Oct 27, 2024, 11:16:00 AMcomponent: f7-cardconfig:
title: Add testNumber to storecontent: =items.testNumber.numericState
Opening this widget after a refresh, but before the first you open the first widget means that the first widget will be properly displayed the first time it opens. The testNumber item is now being tracked as a result of the second widgets expression being called prior to the first widget's use.
I assume there is a very simple solution to this, but after poking around for a few minutes, I admit, I don't see it.
The text was updated successfully, but these errors were encountered:
The problem seems to be that the Item state is not already tracked, and the oh-context constant/var init does not wait for the states.
BTW, I don‘t think that is super easy to fix.
oh-context variables and constant expressions are evaluated before the component is mounted. If the UI is newly opened (or recently reset) any item states are not available via the store when those expression are calculated for the very first time.
Replicate the issue
Here's a basic widget:
All three text outputs should be the same:
However, after a [ctrl + shft + f5] the result is different:
At this point, however, the item is now in the store because of the title expression so any further interaction (refresh the widget, leave the page and come back, etc.) will result in the proper calculations.
Even if you do activities first, for example open some other widgets or pages in the UI, the first time this widget is opened the item states are not properly available.
...except! Here's a second widget:
Opening this widget after a refresh, but before the first you open the first widget means that the first widget will be properly displayed the first time it opens. The testNumber item is now being tracked as a result of the second widgets expression being called prior to the first widget's use.
I assume there is a very simple solution to this, but after poking around for a few minutes, I admit, I don't see it.
The text was updated successfully, but these errors were encountered: