Support a callback function for unstable_viewTransition props #11716
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Quick first pass at supporting
<Link to="/path" unstable_viewTransition={fn}>
wherefn
is(path: Path) => boolean)
- allowing applications to lazily compute the boolean value at click time. The primary use case is large applications where routes are managed in a central manifest - and they need to look up a route in the manifest to know if view transitions should be enabled. This can get prohibitively expensive to do path-matching and looking up routes at render time for all rendered links.I also want to look at supplying
matches
to the callback but that's a bit more involved from an implementation standpoint since we need to move the callback execution down into the guts of therouter
after Fog of War matching has completed.^ I looked into this and it's totally doable, but it feels a bit odd to do this "use location/matches to determine whether to apply a view transition" at the call-site - that feels far more like a global API. If you want this "generic" approach you would probably just end up using your own
Link
wrapper to put this callback on everyLink
in the app. I'm now leaning towards leaving theLink
prop as a boolean (targeted call-site version) and adding a new top-level function you can use globally if you prefer to operate off a manifest: