Skip to content

Commit

Permalink
fix(hooks): export polyfills as a separate entry point (#2529)
Browse files Browse the repository at this point in the history
* fix(hooks): export polyfills as a separate entry point

* docs: changeset

* refactor: use globalThis

* refactor(hooks): expose polyfills as separate entrypoint
  • Loading branch information
emmenko authored May 23, 2023
1 parent 7f7e1e0 commit b6fae35
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/hot-ways-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@commercetools-uikit/hooks': patch
---

Export polyfill as separate entry point. Consumers should import this explicitly in their application when using SSR.
1 change: 0 additions & 1 deletion packages/hooks/index.ts

This file was deleted.

5 changes: 4 additions & 1 deletion packages/hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
"sideEffects": false,
"main": "dist/commercetools-uikit-hooks.cjs.js",
"module": "dist/commercetools-uikit-hooks.esm.js",
"files": ["dist"],
"preconstruct": {
"entrypoints": ["./index.ts", "./polyfills.ts"]
},
"files": ["dist", "polyfills"],
"dependencies": {
"@babel/runtime": "^7.20.13",
"@babel/runtime-corejs3": "^7.20.13",
Expand Down
4 changes: 4 additions & 0 deletions packages/hooks/polyfills/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"main": "dist/commercetools-uikit-hooks-polyfills.cjs.js",
"module": "dist/commercetools-uikit-hooks-polyfills.esm.js"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Polyfill for `MutationObserver` when used with SSR.
global.MutationObserver =
// eslint-disable-next-line no-undef
globalThis.MutationObserver =
typeof window !== 'undefined' && 'MutationObserver' in window
? window.MutationObserver
: class MutationObserver {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// except for the usage of `MutationObserver` instead of `IntersectionObserver`.
import { useEffect, useLayoutEffect, useRef } from 'react';
import rafSchd from 'raf-schd';
import './polyfill';

export type TUseMutationObserverCallback = (
mutationsList: MutationRecord[],
Expand Down

1 comment on commit b6fae35

@vercel
Copy link

@vercel vercel bot commented on b6fae35 May 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.