Skip to content

Commit

Permalink
fix: fix error when previewing attachment on outlook.office.com
Browse files Browse the repository at this point in the history
this fix guards against edge cases where the contentEditable being monitored does not have an
offsetParent, which can happen if the node has position of 'fixed'.

fixes #141
  • Loading branch information
sbrudz committed Jan 11, 2022
1 parent 7240878 commit 3c05d57
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
26 changes: 26 additions & 0 deletions spec/JustNotSorrySpec.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,32 @@ describe('JustNotSorry', () => {
expect(wrapper.state('parentNode')).toBe(domNode.parentNode);
});

describe('when the email node is null', () => {
it('clears the state', () => {
instance.updateWarnings(null, [
buildWarning('\\b!{3,}\\B', 'warning message'),
]);

expect(wrapper.state('warnings').length).toEqual(0);
expect(wrapper.state('parentNode')).toEqual({});
});
});

describe('when the email node has an offsetParent of null', () => {
it('clears the state', () => {
const emailNode = {
offsetParent: null,
childNodes: [],
};
instance.updateWarnings(emailNode, [
buildWarning('\\b!{3,}\\B', 'warning message'),
]);

expect(wrapper.state('warnings').length).toEqual(0);
expect(wrapper.state('parentNode')).toEqual({});
});
});

describe('when there are top-level and child nodes', () => {
it('catches the warnings for both', () => {
const elem = mount(
Expand Down
4 changes: 4 additions & 0 deletions src/components/JustNotSorry.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class JustNotSorry extends Component {
}

updateWarnings(email, patterns) {
if (!email || !email.offsetParent) {
this.resetState();
return;
}
const newWarnings =
email.childNodes.length > 0
? Array.from(email.childNodes)
Expand Down

0 comments on commit 3c05d57

Please sign in to comment.