Skip to content

Conversation

stephencelis
Copy link
Member

@stephencelis stephencelis commented Jul 22, 2025

We currently allow folks to use prepareDependencies in the body of a preview, which works great. It does appear that previews have gotten fancier, especially in Xcode 26, where a preview session stays live even during changes to view code. These changes cause the preview body to re-evaluate, triggering prepareDependencies all over again, and spitting out a large purple warning into the preview console.

The behavior of prepareDependencies is to ignore future calls and surface warnings in to catch misuse, but maybe we should only emit these warnings in the application. Preview environments are a bit treacherous as is, with app entry point code leaking into them, and preview trait code executing across multiple previews in a file. And so this branch proposes silencing this warning in previews entirely.

This PR also removes the warning about ignoring app entry point dependencies in previews, as the warning was not super useful in practice.

We currently allow folks to use `prepareDependencies` in the body of a
preview, which works great. It does appear that previews have gotten
fancier, especially in Xcode 26, where a preview session stays live even
during changes to view code. These changes cause the preview body to
re-evaluate, triggering `prepareDependencies` all over again, and
spitting out a large purple warning into the preview console.

The behavior of `prepareDependencies` is to ignore future calls and
surface warnings in to catch misuse, but maybe we should only emit these
warnings in the application. Preview environments are a bit treacherous
as is, with app entry point code leaking into them, and preview trait
code executing across multiple previews in a file. And so this branch
proposes silencing this warning in previews entirely.

Alternatives:

- We could shorten the warning to a one-liner. Something like "Xcode
  Preview: 'prepareDependencies' already called this session. Ignoring."
- We could stop showing 'prepareDependencies' as a legit tool for
  previews and instead push people towards 'withDependencies', though
  this is not great for ergonomics, especially in non-single entry point
  systems.

Bonus change:

This PR also updates the warning about ignoring app entry point
dependencies in previews with instructions on how to suppress. But given
the above, maybe we actually want to suppress this warning entirely?
@stephencelis stephencelis requested a review from mbrandonw July 22, 2025 23:34
@stephencelis stephencelis marked this pull request as draft July 22, 2025 23:34
It's not super helpful in practice.
@stephencelis stephencelis marked this pull request as ready for review July 30, 2025 20:14
@stephencelis stephencelis merged commit 4d9f64b into main Jul 30, 2025
7 checks passed
@stephencelis stephencelis deleted the preview-ergonomics branch July 30, 2025 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant