Skip to content
Discussion options

You must be logged in to vote

As far as I can tell this is one (of many) quirks of the #Preview macro. If you use the old style of preview provider it works as expected:

struct ContentViewPreview: PreviewProvider {
  static var previews: some View {
    @Shared(.runtimeData) var runtimeData = .mock
    ContentView()
      .frame(width: 300, height: 600)
  }
}

Alternately, you could force a mutation of the @Shared value:

 #Preview {
-  @Previewable @Shared(.runtimeData) var runtimeData = .mock
+  @Previewable @Shared(.runtimeData) var runtimeData
+  let _ = $runtimeData.withLock { $0 = .mock }
   ContentView()
     .frame(width: 300, height: 600)
 }

Because this seems to be a bug/behavior with #Preview and not our libr…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@teleki
Comment options

Answer selected by teleki
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
apple bug Something isn't working due to a bug on Apple's platforms.
2 participants
Converted from issue

This discussion was converted from issue #188 on August 27, 2025 22:39.