Skip to content

.task Modifier Does Not Fire #1

@MatiMax

Description

@MatiMax

Issue

The .task modifier on views seems not to fire.

Tested Environment

The test has been conducted on

  • Ubuntu Server 24.04 LTS with Swift toolchain version 6.3.2
  • macOS Sequoia 15.7.7 with Swift toolchain version 6.2.4.1.4

and TUIKit main branch version.

How to Reproduce

import TUIkit

struct ContentView: View {
    @State private var taskHasRun = false
    
    var body: some View {
        VStack {
            Text("Hello, TUIkit!")
                .foregroundStyle(.palette.accent)
                .bold()
                .task { await flagTaskAsRun() }
                
            Text("Welcome to your new terminal app")
                .foregroundStyle(.palette.foregroundSecondary)
                .task { await flagTaskAsRun() }
            
            Spacer()
            
            Text(".task has \(taskHasRun == true ? "indeed":"not") run")
                .task { await flagTaskAsRun() }
        }
        .padding()
        .task { await flagTaskAsRun() }
    }
    
    func flagTaskAsRun() async {
        taskHasRun = true
    }
}

Observed Behaviour

The following simple test program shows that taskHasRun will never ever be set to true, so the last Text view will display .task has not run.

Expected Behaviour

With either VStack or any of the Text views the function flagTaskAsRun() should be fired and hence taskHasRun should be set to true, so the last Text view should display .task has indeed run.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions