Skip to content

Conversation

@github-actions
Copy link
Contributor

Release
@floating-ui/utils@0.2.8

Diff for packages/utils

Diff
diff --git a/packages/utils/CHANGELOG.md b/packages/utils/CHANGELOG.md
index 7f9072b1..4858aed0 100644
--- a/packages/utils/CHANGELOG.md
+++ b/packages/utils/CHANGELOG.md
@@ -1,5 +1,11 @@
 # @floating-ui/utils
 
+## 0.2.8
+
+### Patch Changes
+
+- fix: make element utils ssr-friendly
+
 ## 0.2.7
 
 ### Patch Changes
diff --git a/packages/utils/package.json b/packages/utils/package.json
index ff969b80..18158bd8 100644
--- a/packages/utils/package.json
+++ b/packages/utils/package.json
@@ -1,6 +1,6 @@
 {
   "name": "@floating-ui/utils",
-  "version": "0.2.7",
+  "version": "0.2.8",
   "description": "Utilities for Floating UI",
   "publishConfig": {
     "access": "public"
diff --git a/packages/utils/src/dom.ts b/packages/utils/src/dom.ts
index b90fea2b..965fc731 100644
--- a/packages/utils/src/dom.ts
+++ b/packages/utils/src/dom.ts
@@ -1,5 +1,9 @@
 type OverflowAncestors = Array<Element | Window | VisualViewport>;
 
+function hasWindow() {
+  return typeof window !== 'undefined';
+}
+
 export function getNodeName(node: Node | Window): string {
   if (isNode(node)) {
     return (node.nodeName || '').toLowerCase();
@@ -21,14 +25,26 @@ export function getDocumentElement(node: Node | Window): HTMLElement {
 }
 
 export function isNode(value: unknown): value is Node {
+  if (!hasWindow()) {
+    return false;
+  }
+
   return value instanceof Node || value instanceof getWindow(value).Node;
 }
 
 export function isElement(value: unknown): value is Element {
+  if (!hasWindow()) {
+    return false;
+  }
+
   return value instanceof Element || value instanceof getWindow(value).Element;
 }
 
 export function isHTMLElement(value: unknown): value is HTMLElement {
+  if (!hasWindow()) {
+    return false;
+  }
+
   return (
     value instanceof HTMLElement ||
     value instanceof getWindow(value).HTMLElement
@@ -36,8 +52,7 @@ export function isHTMLElement(value: unknown): value is HTMLElement {
 }
 
 export function isShadowRoot(value: unknown): value is ShadowRoot {
-  // Browsers without `ShadowRoot` support.
-  if (typeof ShadowRoot === 'undefined') {
+  if (!hasWindow() || typeof ShadowRoot === 'undefined') {
     return false;
   }
 

Full diff
0.2.7...0.2.8.

@DanielleHuisman DanielleHuisman marked this pull request as ready for review September 17, 2024 16:52
@DanielleHuisman DanielleHuisman merged commit f6712cd into main Sep 17, 2024
@DanielleHuisman DanielleHuisman deleted the upstream/utils-0.2.8 branch September 17, 2024 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants