Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

fix(firefox): handle data uris #209

Merged
merged 2 commits into from
Jun 19, 2017
Merged

fix(firefox): handle data uris #209

merged 2 commits into from
Jun 19, 2017

Conversation

oliviertassinari
Copy link
Contributor

@oliviertassinari oliviertassinari commented Jun 12, 2017

Closes #207.

Come into that issue trying to add happo to the storybook of react-instantsearch.

Copy link
Contributor

@lencioni lencioni left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I know we don't have a lot of stuff to help you get this set up on new projects, so let me know if you want any guidance there. I have integrated it with GitHub and Travis on a project and would be happy to share some of our scripts if you would find that helpful. I'd like to make it a lot easier to get set up at some point too (#143).

return new Promise((resolve, reject) => {
// No need to wait for the image to be loaded.
if (url.indexOf('data:image') === 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we might want to be a little more specific with this search. In my experience this was working alright with JPEG data URIs and was actually needed in order for those to be fully rendered by the browser (although I wonder if we should switch to something like createImageBitmap instead). I think this might only be a problem when the data URI is an SVG.

I also wonder if this should be in the promise or if we should add a filter before this function call. Thoughts?

In the project you were trying to add this to, did you encounter this with an SVG data URI or something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have been digging a bit more in the issue. It seems to be a char encoding issue. I haven't went down the rabbit hole yet. Are you saying that even with not network latency, it's preferable to load the image first?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah interesting.

Are you saying that even with not network latency, it's preferable to load the image first?

Yes, because image rendering is non-instant and non-blocking, so screenshots can actually be taken in the middle of image rendering, which makes it so you end up with a lot of visual diffs for components that use images because the screenshots are taken at different moments while the image was rendering. Here's some more info: #162 (comment)

@@ -0,0 +1,13 @@
import { waitForImageToLoad } from '../waitForImagesToRender';

const image = "data:image/svg+xml;utf8,<svg%20viewBox='0%200%2010%2011'%20xmlns='http://www.w3.org/2000/svg'><g%20stroke='%23bfc7d8'%20stroke-width='1.5'%20fill='none'%20fill-rule='evenodd'%20stroke-linecap='round'><path%20d='M5%201.5v8M9%205.5H1'/></g></svg";
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you are missing a > on the end here.

@oliviertassinari
Copy link
Contributor Author

oliviertassinari commented Jun 14, 2017

I have found a better solution closer to the root of the issue. I have noticed that Firefox escape the ' (where Chrome don't).

var url1 = window.getComputedStyle(document.querySelector(X)).getPropertyValue('background-image')

// Firefox: url1 = url("data:image/svg+xml;utf8,<svg%20viewBox=\'0%200%2010%209\'%20xmlns=\'http://www.w3.org/2000/svg\'><path%20d=\'M1%204.88l2.378%202.435L9.046%201.6\'%20stroke-width=\'1.6\'%20stroke=\'%23FFF\'%20fill=\'none\'%20fill-rule=\'evenodd\'%20stroke-linecap=\'round\'%20stroke-linejoin=\'round\'/></svg>")
// Chrome: url1 = url("data:image/svg+xml;utf8,<svg viewBox='0 0 10 9' xmlns='http://www.w3.org/2000/svg'><path d='M1 4.88l2.378 2.435L9.046 1.6' stroke-width='1.6' stroke='%23FFF' fill='none' fill-rule='evenodd' stroke-linecap='round' stroke-linejoin='round'/></svg>")

@oliviertassinari
Copy link
Contributor Author

oliviertassinari commented Jun 14, 2017

so let me know if you want any guidance there

Thanks for asking. I'm gonna try to integrate it with Travis CI, however, I'm planning on hijacking his original purpose to only takes the screenshots with Happo and to let Argos-CI handle the diffs and review process.
The only issue I have seen so far with that integration is around the screenshot destination, original test names are base64 making the folder name harder to use. I'm wondering if you would be open adding a function option for generating the screenshots destination.

Finally, I feel like it would be really interesting to build a selenium grid target. We have been using vrtest on Material-UI to take the screenshots in a docker hosting a selenium grid, chrome & firefox, that works pretty well.

@oliviertassinari
Copy link
Contributor Author

oliviertassinari commented Jun 17, 2017

Now I have a reproduction example for that issue: algolia/react-instantsearch#130. I have managed to make the 82 cases passed with the fix of the PR.

Copy link
Contributor

@trotzig trotzig left a comment

Choose a reason for hiding this comment

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

Thanks for contributing! I left a small suggestion for an improvement. When you're done, let me know and I'll merge and deploy a new version.

@@ -5,7 +5,9 @@ export default function findBackgroundImageUrls(string) {
let match;
// eslint-disable-next-line no-cond-assign
while (match = URL_PATTERN.exec(string)) {
result.push(match[1]);
// We need to unescape the simple quote.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment could be expanded a little to better explain why it's here. How about

Inlined images of the form data:image can contain embedded svg. To avoid failing to load this image, we need to unescape escaped single quotes.

@lencioni
Copy link
Contributor

I'm wondering if you would be open adding a function option for generating the screenshots destination.

I'm hesitant to open this up to be customized because I'm not sure how useful it would be for most people. However, we have been discussing changing how we approach uploading in #178. Do you think something like that would fit your use-case?

@lencioni lencioni merged commit efb16e2 into Galooshi:master Jun 19, 2017
@oliviertassinari oliviertassinari deleted the image-data branch June 19, 2017 18:37
@oliviertassinari
Copy link
Contributor Author

oliviertassinari commented Jun 19, 2017

Thanks guys :).

I'm hesitant to open this up to be customized

@lencioni I can understand, I ended up writing a normalisation script. Without looking too much in details, I don't think that #178 would answer my issue.

@trotzig
Copy link
Contributor

trotzig commented Jun 20, 2017

This was released in version 5.0.0-rc.6. Thanks @oliviertassinari!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants