Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset Global Page State #663

Open
pdt-ayidi opened this issue Oct 22, 2022 · 1 comment
Open

Reset Global Page State #663

pdt-ayidi opened this issue Oct 22, 2022 · 1 comment
Labels
🐛 bug Something isn't working

Comments

@pdt-ayidi
Copy link

The problem

After the introduction of #592, the global state (styles, etc.) of the page are not reset across snapshots. We came across this issues when testing modals, libraries like bootstrap edit the body element. A possible solution is to provide an option to refresh the page per snapshot.

Our workaround solution is to add this to preview.jsx:

channel.on(CURRENT_STORY_WAS_SET, () => {
  // reset global state here...
  document.body.removeAttribute('style');
});

Environment

Percy/v1
@percy/client/1.10.3
@percy/storybook/4.3.3 (node/v14.16.0; storybook/6.5.9; buildkite)

Browsers
Firefox 95.0
Chrome 96.0

Code to reproduce issue

// simulate snapshot by using storybook's channel
window.__STORYBOOK_PREVIEW__?.channel.emit('setCurrentStory', { storyId: '<story-1>' });

// story-1 sets a global property
document.body.style.paddingRight = '16px'

// navigate to another story
window.__STORYBOOK_PREVIEW__?.channel.emit('setCurrentStory', { storyId: '<story-2>' });

// body will have 'padding-right: 16px', expected ''
document.body.style.paddingRight
@github-actions
Copy link

github-actions bot commented Nov 8, 2022

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.

@github-actions github-actions bot added the 🍞 stale Closed due to inactivity label Nov 8, 2022
@itsjwala itsjwala added ✨ enhancement New feature or request and removed 🍞 stale Closed due to inactivity labels Nov 21, 2022
@itsjwala itsjwala added 🐛 bug Something isn't working and removed ✨ enhancement New feature or request labels Jan 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants