Skip to content

Commit

Permalink
Remove dom-helpers, add lib/canUseDom (#1066)
Browse files Browse the repository at this point in the history
Remove an unneeded dependency on dom-helpers and simply add a local replacement
for determining that we can use the dom (or essentially that we are in a
browser).
  • Loading branch information
tggreene committed Oct 6, 2020
1 parent fdac701 commit 630fa25
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 14 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"@types/react-transition-group": "^4.4.0",
"arrify": "^1.0.1",
"classnames": "^2.2.6",
"dom-helpers": "^3.2.1",
"downshift": "^5.2.0",
"fuzzaldrin-plus": "^0.6.0",
"glamor": "^2.20.40",
Expand Down
1 change: 1 addition & 0 deletions src/lib/canUseDom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default Boolean(typeof window !== 'undefined' && window.document)
2 changes: 1 addition & 1 deletion src/portal/src/Portal.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component } from 'react'
import canUseDom from 'dom-helpers/util/inDOM'
import ReactDOM from 'react-dom'
import PropTypes from 'prop-types'
import canUseDom from '../../lib/canUseDom'

let portalContainer

Expand Down
3 changes: 2 additions & 1 deletion src/ssr/src/autoHydrate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { hydrate as boxHydrate } from 'ui-box'
import { rehydrate } from 'glamor'
import canUseDom from '../../lib/canUseDom'

/**
* You shouldn't have to manually run this.
Expand All @@ -16,7 +17,7 @@ export function hydrate(hydration) {
}

export default function autoHydrate() {
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
if (canUseDom) {
const hydration = document.querySelector('#evergreen-hydrate')

if (hydration) {
Expand Down
6 changes: 2 additions & 4 deletions src/toaster/src/Toaster.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import React from 'react'
import ReactDOM from 'react-dom'
import canUseDom from '../../lib/canUseDom'
import ToastManager from './ToastManager'

const isBrowser =
typeof window !== 'undefined' && typeof window.document !== 'undefined'

/**
* The Toaster manages the interactions between
* the ToasterManger and the toast API.
*/
export default class Toaster {
constructor() {
if (!isBrowser) return
if (!canUseDom) return

const container = document.createElement('div')
container.setAttribute('data-evergreen-toaster-container', '')
Expand Down
7 changes: 0 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4734,13 +4734,6 @@ dom-converter@^0.2:
dependencies:
utila "~0.4"

dom-helpers@^3.2.1:
version "3.4.0"
resolved "https://registry.yarnpkg.com/dom-helpers/-/dom-helpers-3.4.0.tgz#e9b369700f959f62ecde5a6babde4bccd9169af8"
integrity sha512-LnuPJ+dwqKDIyotW1VzmOZ5TONUN7CwkCR5hrgawTUbkBGYdeoNLZo6nNfGkCrjtE1nXXaj7iMMpDa8/d9WoIA==
dependencies:
"@babel/runtime" "^7.1.2"

dom-helpers@^5.0.1:
version "5.1.4"
resolved "https://registry.yarnpkg.com/dom-helpers/-/dom-helpers-5.1.4.tgz#4609680ab5c79a45f2531441f1949b79d6587f4b"
Expand Down

0 comments on commit 630fa25

Please sign in to comment.