seek-oss / playroom

Design with JSX, powered by your own component library.
MIT License
4.48k stars 182 forks source link

Fix iframe re-loading when serving certain fixtures #358

Closed askoufis closed 4 months ago

askoufis commented 4 months ago

When serving either the basic or the typescript fixture locally (via build:basic && serve:basic or build:typescript && serve:typescript), each iframe would re-load on every code change. This shouldn't happen when using paramType: 'hash' because hash replacements typically don't cause page navigation.

It turns out that the culprit was the default behaviour of the serve CLI. By default, cleanUrls is true. This results in all requests for .html files being redirected to the same path but without .html (see screenshot). This was occurring for iframe updates, which point directly to /frame.html, resulting in a navigation and full re-load of the frame.

image

The fix is to exclude /frame.html from this behaviour by configuring this inside a serve.json file in each fixture directory.

It turns out the themed fixture already had a serve.json configuration, but it was just blanket-disabling this behaviour for all paths, which doesn't really achieve anything, but it means that you have to explicitly navigate to /index.html to get the themed fixture to load locally, which is annoying.

[!NOTE] If you test this locally, you might still see the full re-load happening. This is probably due to your browser cache. Disabling it for the page, or forcing a full page reload should fix it.

changeset-bot[bot] commented 4 months ago

⚠️ No Changeset found

Latest commit: eea86d207e75895a09d9d763118f5e8141878fa0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR