Skip to content

Commit

Permalink
Merge pull request #426 from chromaui/srcset
Browse files Browse the repository at this point in the history
add a FAQ on srcset
  • Loading branch information
winkerVSbecks authored May 15, 2024
2 parents b418570 + 73e37c0 commit 12546a3
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 6 deletions.
77 changes: 71 additions & 6 deletions src/content/snapshot/snapshots.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ A snapshot is an image of a story plus some metadata captured by a standardized

## Table of contents:

- [View snapshots for a story](#view-snapshots-for-a-story)
- [How are snapshots captured?](#how-are-snapshots-captured)
- [Improve snapshot consistency](#improve-snapshot-consistency)
- [Debug snapshot rendering](#debug-snapshot-rendering)
- [Rerun builds to retake snapshots](#rerun-builds-to-retake-snapshots)
- [Browser differences between snapshots](#browser-differences-between-snapshots)
- [Snapshots](#snapshots)
- [Table of contents:](#table-of-contents)
- [View snapshots for a story](#view-snapshots-for-a-story)
- [How are snapshots captured?](#how-are-snapshots-captured)
- [Improve snapshot consistency](#improve-snapshot-consistency)
- [Debug snapshot rendering](#debug-snapshot-rendering)
- [Rerun builds to retake snapshots](#rerun-builds-to-retake-snapshots)
- [Browser differences between snapshots](#browser-differences-between-snapshots)

<div class="aside">

Expand Down Expand Up @@ -102,6 +104,69 @@ If your resources are behind a firewall, whitelist our domain so we can load you

</details>

<details>
<summary>Why am I seeing inconsistent snapshots for a component using srcset?</summary>

The `srcset` attribute is a useful mechanism that provides the browser with a list of potential images to display, based on specified conditions such as media queries.

In most cases, Chromatic will capture the correct image from the `srcset` list. However, if multiple tests list the same image in their respective `srcset` lists, browser cache issues can result in inconsistent snapshots.

In situations like this, the best workaround is to make the `srcset` URLs unique for each test by adding a random query parameter value.

For instance, one test could have a srcset with a query parameter of `?cachebuster=1714593641616`.

```html
<picture>
<source
sizes="(max-width: 768px) 100vw, 50vw"
type="image/webp"
srcset="
​ https://placehold.co/384x384.webp?cachebuster=1714593641616 384w,
​ https://placehold.co/640x640.webp?cachebuster=1714593641616 640w,
​ https://placehold.co/750x750.webp?cachebuster=1714593641616 750w"
/>
<img
alt="Alt text"
loading="eager"
width="1500"
height="1500"
decoding="async"
sizes="(max-width: 768px) 100vw, 50vw"
src="https://placehold.co/3840x3840.jpeg"
style="color: transparent;"
/>
</picture>
```

If another test uses the same images, they can alter the query parameter in the URL to `?currenttime=1714593641620`.

```html
<picture>
<source
sizes="(max-width: 768px) 100vw, 50vw"
type="image/webp"
srcset="
​ https://placehold.co/384x384.webp?currenttime=1714593641620 384w,
​ https://placehold.co/640x640.webp?currenttime=1714593641620 640w,
​ https://placehold.co/750x750.webp?currenttime=1714593641620 750w"
/>
<img
alt="Alt text"
loading="eager"
width="1500"
height="1500"
decoding="async"
sizes="(max-width: 768px) 100vw, 50vw"
src="https://placehold.co/3840x3840.jpeg"
style="color: transparent;"
/>
</picture>
```

Any query parameter name can be used, just so long as the value is unique to each test.

</details>

<details>
<summary>Why do my emojis look different in the snapshot versus on my machine?</summary>

Expand Down
1 change: 1 addition & 0 deletions src/styles/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const base = css`
font-size: 85%; // Relative font size based on size of surrounding text
line-height: 1;
-webkit-text-size-adjust: 100%;
padding: 3px 5px;
color: inherit;
Expand Down

1 comment on commit 12546a3

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.