Skip to content

Commit

Permalink
SRPanel: small optimisation to only call document.querySelector once (#…
Browse files Browse the repository at this point in the history
…2895)

* Small optimisation to only call document.querySelector once, rather than 3 times

* Added changeset file
  • Loading branch information
sponglord authored Oct 11, 2024
1 parent 683a570 commit 154be9a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/quiet-masks-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@adyen/adyen-web': patch
---

Small optimisation to only call document.querySelector once, rather than three times
11 changes: 8 additions & 3 deletions packages/lib/src/core/Errors/SRPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,29 @@ export class SRPanel extends BaseElement<SRPanelProps> {

constructor(checkout: ICore, props?: SRPanelProps) {
super(checkout, props);

this.id = this.props.id;
this.showPanel = process.env.NODE_ENV !== 'production' ? this.props.showPanel : false;
this._enabled = false;
this._moveFocus = this.props.moveFocus ?? true;

if (this.props.enabled) {
this._enabled = true;
if (document.querySelector(this.props.node)) {

const panelParent = document.querySelector(this.props.node);

if (panelParent) {
const preExistingSRPanel = document.getElementById(this.id);
if (preExistingSRPanel) {
document.querySelector(this.props.node).removeChild(preExistingSRPanel);
panelParent.removeChild(preExistingSRPanel);
}

this.srPanelContainer = document.createElement('div');
this.srPanelContainer.className = 'sr-panel-holder';
this.srPanelContainer.id = this.id;

document.querySelector(this.props.node).appendChild(this.srPanelContainer);
panelParent.appendChild(this.srPanelContainer);

this.mount(this.srPanelContainer);
} else {
throw new Error('Component could not mount. Root node was not found.');
Expand Down

0 comments on commit 154be9a

Please sign in to comment.