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

State vars have to be first #190

Closed
j-f1 opened this issue Jul 16, 2020 · 1 comment · Fixed by #191
Closed

State vars have to be first #190

j-f1 opened this issue Jul 16, 2020 · 1 comment · Fixed by #191
Assignees
Labels
bug Something isn't working

Comments

@j-f1
Copy link
Member

j-f1 commented Jul 16, 2020

If any non-state variables precede state variables, Tokamak crashes when the state variables are read.

Repro:

struct ThisView: View {
  let foo = 3
  @State var bar = 4

  @ViewBuilder var body: some View {
    Text("\(bar)")
  }
}

Encountered in #129.

This happens because StackReconciler#render(compositeView:) enumerates all the properties, resulting in it providing non-consecutive ids to setupState. A potential fix is to declare a var stateIdx outside of the loop and manually increment it when initializing each state variable.

https://github.com/swiftwasm/Tokamak/blob/ffa686c7dca8d454e88246ed2ba7106dee6c4836/Sources/TokamakCore/StackReconciler.swift#L115-L121

@j-f1 j-f1 added the bug Something isn't working label Jul 16, 2020
@MaxDesiatov
Copy link
Collaborator

The proposed fix seems totally legit, let me know if you're submitting a PR for it, otherwise I'll pick it up soon-ish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants