fix: preview iframe URL state sync #9095
Open
+60
−278
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.
Fixes an issue where previous themes would be stuck after switching items or base library.
There were a couple of issues:
initialParamswere never updated)The proposed refactor is to keep the iframe URL as the source of truth within it, and sync it to the host's URL from the outside:
postMessage. The iframe then applies those to its own internal URL, using nuqs (in shallow + replace mode) to benefit from the time-safety (URL throttling shared between host & iframe).Note: some dead code was found and removed in the process:
One thing I noticed while testing is that in production, pressing R to randomise emits two RSC requests (with identical search params aside from the _rsc marker), but only one in development.
Note: it also fixes an issue where pressing the Back button erased the ability to move forward. We can now use Back/Forward to time-travel navigate theme changes, allowing for A/B testing.