I submitted a lightning component to the Security Review. They reported an issue regarding Illegal DOM Access
.
I used the following code in my helper and security review team reported it has an issue.
function setDuration(sld, flag, duration) {
if(flag) {
if(!duration) {
duration = helper.default_duration;
}
return window.setInterval(function(){
sld.next(sld.current + 1); //Switch to the next item on regular interval.
}, duration);
}
}
The reason they gave us is below:
Components are allowed to touch only their own DOM. The exception is the window object, which is used in this helper. If the component is setting events to Window, it needs to
- clean itself up on re-render and
- verify that the component still exists when the event fires
To solve the second point is to check the component is valid or not. So I modified the code as below.
function setDuration(sld, flag, duration, component) {
if(flag) {
if(!duration) {
duration = helper.default_duration;
}
return window.setInterval(function(){
if(component.isValid()) {
sld.next(sld.current + 1); //Switch to the next item on regular interval.
}
}, duration);
}
}
But I could not understand what they are telling in the first point. Any help will be appreciated.