-
Notifications
You must be signed in to change notification settings - Fork 2
Removing percy attribute before truncate #188
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR reorders operations in the getSource function to remove Percy data attributes from the source HTML before truncation, preventing these unwanted attributes from appearing in the final output if truncation occurs at a point that would otherwise preserve them.
Changes:
- Modified the order of operations to apply regex filtering before truncation instead of after
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lib/core/utils/dq-element.js
Outdated
| const regex = /\s*data-percy-[^=]+="[^"]*"/g; | ||
| htmlString = htmlString.replace(regex, ''); | ||
| const regex = /\s*data-percy-[^=]+="[^"]*"/g; // Remove unwanted attributes | ||
| source = source.replace(regex, ''); |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will throw a TypeError if source is null or undefined. The replace operation should be performed after ensuring source has a value, or use optional chaining: source = (source || '').replace(regex, '')
| source = source.replace(regex, ''); | |
| source = (source || '').replace(regex, ''); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lib/core/utils/dq-element.js
Outdated
| htmlString = htmlString.replace(regex, ''); | ||
| const regex = /\s*data-percy-[^=]+="[^"]*"/g; // Remove unwanted attributes | ||
| source = (source || '').replace(regex, ''); | ||
| const htmlString = truncate(source || ''); |
Copilot
AI
Feb 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The parameter passed to truncate is source || '', but this is redundant since source was already ensured to be a string on line 179 where it was assigned the result of (source || '').replace(regex, ''). If source was falsy before line 179, it's now an empty string, so the || '' fallback in line 180 is unnecessary.
| const htmlString = truncate(source || ''); | |
| const htmlString = truncate(source); |
<< Describe the changes >>
Closes: