question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to handle responsive DOM changes

See original GitHub issue

I have been playing around with this library and I noticed something querky in terms of my screen shots. It seems when I set the widths option within cy.percySnapshot the screenshot is taken during the resize of the screen which causes layout issues. By this I mean the screenshot is happening while the layout is still repositioning itself based on the response styles. Is it possible to delay the snapshot a little bit after the width has been set?

Packages: @percy/cypress: 2.3.1 cypress: 4.3.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Robdel12commented, Apr 2, 2020

Hey @jarretmoses, thanks for the issue! I suspect something else is going on. It sounds like your apps DOM changes between widths? The way Percy works is by capturing the DOM of the page (and its state) when percySnapshot is called. When then do asset discovery on the DOM & send it off to the API where its rendered concurrently across browsers & widths.

If your applications DOM changes when the browser is resized, this current method doesn’t work. We render that same DOM at different widths with JS disabled (to prevent JS from altering any captured state). This method assumes the DOM stays the same and you’re using CSS media queries entirely to alter the page.

To fix this you’ll have to resize the test browser before calling percySnapshot for accurate snapshots.

// A helper to make this easy, feel free to edit
Cypress.Commands.add('percyResponsiveSnapshot', (name, width, options = {}) => {
  delete options.widths // we never want to use those in this helper

  cy
    // https://docs.cypress.io/api/commands/viewport.html#Syntax
    .viewport(width)
    .percySnapshot(`${name} - ${width}`, { widths: [width], ...options })
    // Set back the orignal width if you'd like
    //.viewport()
});

// usage:
cy.percyResponsiveSnapshot('Homepage', 320) 
0reactions
github-actions[bot]commented, Aug 3, 2021

This issue is stale because it has been open for more than 14 days with no activity. Remove stale label or comment or this will be closed in 14 days.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How should I handle DOM changes in responsive design?
Essentially, use a CSS table and a media query to swap table values as the viewport changes. CSS .header{ display:table-header-group; } .
Read more >
How to handle responsive DOM changes #392 - GitHub
I suspect something else is going on. It sounds like your apps DOM changes between widths? The way Percy works is by capturing...
Read more >
How to make Grid Responsive on DOM layout changes?
To make grid responsive on DOM layout changes, we can use the windowonresize method of ejGrid. For example, we have placed the Grid...
Read more >
3 Ways To Implement Responsive Design In Your React App
Tracking changes to the window size (width/height); Add/Remove/Update the necessary DOM elements to reflect those changes. The Demo.
Read more >
10 Ways to Minimize Reflows and Improve Performance
1. Use Best-Practice Layout Techniques · 2. Minimize the Number of CSS Rules · 3. Minimize DOM depths · 4. Update Classes Low...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found