Skip to content

Commit

Permalink
fix: correct WeakRef for old Safari. fixes #68
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Apr 6, 2024
1 parent 3c64d15 commit 3e79b5f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .size.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"name": "dist/es2015/index.js",
"passed": true,
"size": 3378,
"size": 3421,
"sizeLimit": 3600
}
]
6 changes: 6 additions & 0 deletions src/return-focus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ function weakRef(value: Element | null): null | Ref;
function weakRef(value: Element | null): SetRef | Ref | null {
if (!value) return null;

// #68 Safari 14.1 dont have it yet
// FIXME: remove in 2025
if (typeof WeakRef === 'undefined') {
return () => value || null;
}

const w = value ? new WeakRef(value) : null;

return () => w?.deref() || null;
Expand Down

0 comments on commit 3e79b5f

Please sign in to comment.