Skip to content

DynamicPreferenceCombiner returns early causing subsequent views in ForEach to not render #669

@Kyle-Ye

Description

@Kyle-Ye

Description

When a view that does not return a display list (such as Spacer) is placed in a dynamic container like ForEach, any subsequent views fail to render because their display lists are never combined.

Reproduction

struct ContentView: View {
    var body: some View {
        VStack {
            Color.red
            Color.green
            ForEach(0 ..< 1) { index in
                Spacer()
                Color.blue
            }
        }
    }
}

In this example, Color.blue fails to render because Spacer before it does not return a display list, causing DynamicPreferenceCombiner to return early.

Root Cause

An item in a dynamic container may be missing a preference if it does not return a display list:

struct MyEmptyView: View, PrimitiveView, UnaryView {
    func _makeView(view: _GraphValue<Self>, inputs: _ViewInputs) -> _ViewOutputs {
        _ViewOutputs()
    }
}

Spacer is an example of such a view. When placed in a dynamic list, the preference combining logic returns early, preventing subsequent views from being processed.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions