Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility of the dialog-polyfill with isomorphic environments #2497

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/calm-cobras-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sumup/circuit-ui": patch
---

Fixed polyfill for the `dialog` element to work in isomorphic environments.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ package-lock.json
# disable linting for templates because it will have its own rules when used in a new app
packages/cna-template/template
packages/astro-template/src/env.d.ts
packages/circuit-ui/vendor
14 changes: 1 addition & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/circuit-ui/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ __reports__/
*rc.js
tsconfig.json
scripts/
vendor/
2 changes: 1 addition & 1 deletion packages/circuit-ui/components/Toggletip/Toggletip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ import {
type Placement,
type Side,
} from '@floating-ui/react-dom';
import dialogPolyfill from 'dialog-polyfill';

import dialogPolyfill from '../../vendor/dialog-polyfill/index.js';
import type { ClickEvent } from '../../types/events.js';
import { clsx } from '../../styles/clsx.js';
import { applyMultipleRefs } from '../../util/refs.js';
Expand Down
1 change: 0 additions & 1 deletion packages/circuit-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
"dependencies": {
"@floating-ui/react-dom": "^2.1.0",
"@nanostores/react": "^0.7.2",
"dialog-polyfill": "^0.5.6",
"nanostores": "^0.10.3",
"react-modal": "^3.16.1",
"react-number-format": "5.3.0",
Expand Down
27 changes: 27 additions & 0 deletions packages/circuit-ui/vendor/dialog-polyfill/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3 changes: 3 additions & 0 deletions packages/circuit-ui/vendor/dialog-polyfill/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# dialog-polyfill

This code was copied from [GoogleChrome/dialog-polyfill](https://github.com/GoogleChrome/dialog-polyfill), specifically [GoogleChrome/dialog-polyfill#231](https://github.com/GoogleChrome/dialog-polyfill/pull/231), which adds support for safely importing the polyfill in isomorphic environments.
17 changes: 17 additions & 0 deletions packages/circuit-ui/vendor/dialog-polyfill/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
interface DialogPolyfillType {
registerDialog(dialog: HTMLDialogElement): void;
forceRegisterDialog(dialog: HTMLDialogElement): void;
}

/**
* If used as CJS, then "dialogPolyfill" is added to the global scope. Just assert it exists.
*/
declare global {
const dialogPolyfill: DialogPolyfillType;
}

/**
* If used as ESM, then we export a const of type "DialogPolyfillType" as the default.
*/
declare const dialogPolyfill: DialogPolyfillType;
export default dialogPolyfill;
Loading
Loading