Skip to content

Commit 73893a2

Browse files
Lior Belinskydiasbruno
Lior Belinsky
authored andcommitted
[fixed] Safety check for SSR (#668)
- add missing test for string appElement - add safety check for using setElement on ssr - fix minor typo
1 parent 5f92df7 commit 73893a2

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

Diff for: specs/Modal.spec.js

+22
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,28 @@ export default () => {
8484
ReactDOM.unmountComponentAtNode(node);
8585
});
8686

87+
it("allow setting appElement of type string", () => {
88+
const node = document.createElement("div");
89+
class App extends Component {
90+
render() {
91+
return (
92+
<div>
93+
<Modal isOpen>
94+
<span>hello</span>
95+
</Modal>
96+
</div>
97+
);
98+
}
99+
}
100+
const appElement = "body";
101+
Modal.setAppElement(appElement);
102+
ReactDOM.render(<App />, node);
103+
document.body
104+
.querySelector(".ReactModalPortal")
105+
.parentNode.should.be.eql(document.body);
106+
ReactDOM.unmountComponentAtNode(node);
107+
});
108+
87109
it("default parentSelector should be document.body.", () => {
88110
const modal = renderModal({ isOpen: true });
89111
modal.props.parentSelector().should.be.eql(document.body);

Diff for: src/helpers/ariaAppHider.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import warning from "warning";
2+
import { canUseDOM } from "./safeHTMLElement";
23

34
let globalElement = null;
45

@@ -12,7 +13,7 @@ export function assertNodeList(nodeList, selector) {
1213

1314
export function setElement(element) {
1415
let useElement = element;
15-
if (typeof useElement === "string") {
16+
if (typeof useElement === "string" && canUseDOM) {
1617
const el = document.querySelectorAll(useElement);
1718
assertNodeList(el, useElement);
1819
useElement = "length" in el ? el[0] : el;

0 commit comments

Comments
 (0)