Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Item states not tracked at context variable and constant evaluation #2842

Open
JustinGeorgi opened this issue Oct 27, 2024 · 1 comment
Open
Labels
bug Something isn't working main ui Main UI

Comments

@JustinGeorgi
Copy link
Contributor

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-error
tags: []
props:
  parameters: []
  parameterGroups: []
timestamp: Oct 27, 2024, 11:04:06 AM
component: oh-context
config:
  constants:
    testItemConst: =`testNumber state is ${items.testNumber.state}`
  variables:
    testItemVar: =`testNumber state is ${items.testNumber.state}`
slots:
  default:
    - component: f7-card
      config:
        title: =`testNumber state is ${items.testNumber.state}`
        content: =const.testItemConst
        footer: =vars.testItemVar

All three text outputs should be the same:
image

However, after a [ctrl + shft + f5] the result is different:
image

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-2
tags: []
props:
  parameters: []
  parameterGroups: []
timestamp: Oct 27, 2024, 11:16:00 AM
component: f7-card
config:
  title: Add testNumber to store
  content: =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.

@JustinGeorgi JustinGeorgi added bug Something isn't working main ui Main UI labels Oct 27, 2024
@florian-h05
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working main ui Main UI
Projects
None yet
Development

No branches or pull requests

2 participants