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

Infinite loop with TextField on iOS 15 #8316

Open
bogdan-pechounov opened this issue Jul 25, 2023 · 0 comments
Open

Infinite loop with TextField on iOS 15 #8316

bogdan-pechounov opened this issue Jul 25, 2023 · 0 comments

Comments

@bogdan-pechounov
Copy link

bogdan-pechounov commented Jul 25, 2023

How frequently does the bug occur?

Sometimes

Description

When I type on a suggestion in the keyboard, sometimes the UI freezes because of an infinite loop, or I get a Binding<String> action tried to update multiple times per frame.. This happens on the "iPhone SE (1st generation) - iOS 15.0" emulator inconsistently. On my physical device running iOS 15.7.8, it seems to always happen. It doesn't seem to happen for iOS 16.

Simulator Screenshot - iPhone SE (1st generation) - 2023-07-25 at 13 41 05

(UI is frozen after pressing the "Imagine" suggestion)

Stacktrace & log output

There is no crash. I added let _ = print(item.name) and the name keeps being printed.

Imagine
Imagine
Imagine
Imagine
Imagine
Imagine
...

Can you reproduce the bug?

Sometimes

Reproduction Steps

  1. Add an item
  2. Focus on the item
  3. Select a suggestion on the mobile keyboard
  4. Sometimes the error doesn't happen on the first try, in which case run the app again
struct ContentView: View {
    var body: some View {
        ItemsView2()
    }
}
import SwiftUI
import RealmSwift

class Item2: Object, ObjectKeyIdentifiable {
    @Persisted(primaryKey: true) var _id: ObjectId
    @Persisted var name: String
    @Persisted var order: Int
}


struct ItemsView2: View {
    @ObservedResults(Item2.self, sortDescriptor: SortDescriptor(keyPath: "order", ascending: true)) var items // maybe the sorting is the cause
    
    var body: some View {
        NavigationView {
            // List
            List {
                Section {
                    ForEach(items) { item in
                        ItemView2(item: item)
                    }
                    .onDelete(perform: $items.remove)
                    
                    // Add
                    Button("Add") {
                        let item = Item2()
                        item.order = (items.max(of: \Item2.order) ?? 0) + 1
                        $items.append(item)
                    }
                }
            }
        }
    }
}

struct ItemView2: View {
    @ObservedRealmObject var item: Item2
    
    var body: some View {
        
        let _ = print(item.name)
        
        HStack { // not sure if it makes a difference
            TextField("Item", text: $item.name)
        }
    }
}

Version

13.17.0

What Atlas Services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

iOS 15

Build environment

Xcode version: 14.3.1
Dependency manager and version: none?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant