Skip to content
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
41 changes: 24 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
# rc-dialog
# @rc-component/dialog

react dialog component
react dialog component.

[![NPM version][npm-image]][npm-url] [![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi) [![build status][github-actions-image]][github-actions-url] [![Test coverage][codecov-image]][codecov-url] [![npm download][download-image]][download-url] [![bundle size][bundlephobia-image]][bundlephobia-url]
[![NPM version][npm-image]][npm-url] [![npm download][download-image]][download-url] [![build status][github-actions-image]][github-actions-url] [![Codecov][codecov-image]][codecov-url] [![bundle size][bundlephobia-image]][bundlephobia-url] [![dumi][dumi-image]][dumi-url]

[npm-image]: http://img.shields.io/npm/v/rc-dialog.svg?style=flat-square
[npm-url]: http://npmjs.org/package/rc-dialog
[github-actions-image]: https://github.com/react-component/dialog/workflows/CI/badge.svg
[github-actions-url]: https://github.com/react-component/dialog/actions
[circleci-image]: https://img.shields.io/circleci/react-component/dialog/master?style=flat-square
[circleci-url]: https://circleci.com/gh/react-component/dialog
[npm-image]: https://img.shields.io/npm/v/@rc-component/dialog.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@rc-component/dialog
[travis-image]: https://img.shields.io/travis/react-component/dialog/master?style=flat-square
[travis-url]: https://travis-ci.com/react-component/dialog
[github-actions-image]: https://github.com/react-component/dialog/actions/workflows/ci.yml/badge.svg
[github-actions-url]: https://github.com/react-component/dialog/actions/workflows/ci.yml
[codecov-image]: https://img.shields.io/codecov/c/github/react-component/dialog/master.svg?style=flat-square
[codecov-url]: https://app.codecov.io/gh/react-component/dialog
[download-image]: https://img.shields.io/npm/dm/rc-dialog.svg?style=flat-square
[download-url]: https://npmjs.org/package/rc-dialog
[bundlephobia-url]: https://bundlephobia.com/result?p=rc-dialog
[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/rc-dialog
[david-url]: https://david-dm.org/react-component/dialog
[david-image]: https://david-dm.org/react-component/dialog/status.svg?style=flat-square
[david-dev-url]: https://david-dm.org/react-component/dialog?type=dev
[david-dev-image]: https://david-dm.org/react-component/dialog/dev-status.svg?style=flat-square
Comment on lines +9 to +18

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

There are several unused badge definitions here for Travis CI and David DM. To keep the documentation clean and maintainable, it's best to remove definitions that aren't being used in the badge list at the top of the file.

Suggested change
[travis-image]: https://img.shields.io/travis/react-component/dialog/master?style=flat-square
[travis-url]: https://travis-ci.com/react-component/dialog
[github-actions-image]: https://github.com/react-component/dialog/actions/workflows/ci.yml/badge.svg
[github-actions-url]: https://github.com/react-component/dialog/actions/workflows/ci.yml
[codecov-image]: https://img.shields.io/codecov/c/github/react-component/dialog/master.svg?style=flat-square
[codecov-url]: https://app.codecov.io/gh/react-component/dialog
[download-image]: https://img.shields.io/npm/dm/rc-dialog.svg?style=flat-square
[download-url]: https://npmjs.org/package/rc-dialog
[bundlephobia-url]: https://bundlephobia.com/result?p=rc-dialog
[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/rc-dialog
[david-url]: https://david-dm.org/react-component/dialog
[david-image]: https://david-dm.org/react-component/dialog/status.svg?style=flat-square
[david-dev-url]: https://david-dm.org/react-component/dialog?type=dev
[david-dev-image]: https://david-dm.org/react-component/dialog/dev-status.svg?style=flat-square
[github-actions-image]: https://github.com/react-component/dialog/actions/workflows/ci.yml/badge.svg
[github-actions-url]: https://github.com/react-component/dialog/actions/workflows/ci.yml
[codecov-image]: https://img.shields.io/codecov/c/github/react-component/dialog/master.svg?style=flat-square
[codecov-url]: https://app.codecov.io/gh/react-component/dialog

[download-image]: https://img.shields.io/npm/dm/@rc-component/dialog.svg?style=flat-square
[download-url]: https://npmjs.org/package/@rc-component/dialog
[bundlephobia-url]: https://bundlephobia.com/package/@rc-component/dialog
[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/@rc-component/dialog
[dumi-url]: https://github.com/umijs/dumi
[dumi-image]: https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square


## Screenshot

Expand All @@ -29,12 +36,12 @@ online example: https://dialog.react-component.vercel.app/

## Install

[![rc-dialog](https://nodei.co/npm/rc-dialog.png)](https://npmjs.org/package/rc-dialog)
[![@rc-component/dialog](https://nodei.co/npm/@rc-component/dialog.png)](https://npmjs.org/package/@rc-component/dialog)

## Usage

```js
var Dialog = require('rc-dialog');
var Dialog = require('@rc-component/dialog');

ReactDOM.render(
<Dialog title={title} onClose={callback1} visible>
Expand All @@ -47,7 +54,7 @@ ReactDOM.render(

## API

### rc-dialog
### @rc-component/dialog

| Name | Type | Default | Description | Version |
| --- | --- | --- | --- | --- |
Expand Down Expand Up @@ -102,7 +109,7 @@ open coverage/ dir

## License

rc-dialog is released under the MIT license.
@rc-component/dialog is released under the MIT license.


## 🤝 Contributing
Expand Down
28 changes: 28 additions & 0 deletions tests/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,31 @@ console.error = (...args) => {

originError(...args);
};

window.MessageChannel = class {
port1;
port2;
constructor() {
const createPort = () => {
const port = {
onmessage: null,
postMessage: (message) => {
setTimeout(() => {
if (port._target && typeof port._target.onmessage === 'function') {
port._target.onmessage({ data: message });
}
}, 0);
},
_target: null,
};
return port;
};

const port1 = createPort();
const port2 = createPort();
port1._target = port2;
port2._target = port1;
this.port1 = port1;
this.port2 = port2;
}
}
Comment on lines +28 to +54

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for MessageChannel usage patterns
echo "=== MessageChannel direct usage ==="
rg -n "MessageChannel" -C2

echo -e "\n=== addEventListener with 'message' ==="
rg -n "addEventListener\s*\(\s*['\"]message['\"]" -C2

echo -e "\n=== removeEventListener usage ==="
rg -n "removeEventListener" -C2

echo -e "\n=== port.close usage ==="
rg -n "\.close\s*\(" -C2 | grep -i "port\|channel" -C2

Repository: react-component/dialog

Length of output: 347


🏁 Script executed:

#!/bin/bash
# Check if setup.js is imported/required anywhere
echo "=== setup.js imports/requires ==="
rg -n "setup\.js" -C2

echo -e "\n=== Check for dynamic MessageChannel access ==="
rg -n "\[.*MessageChannel.*\]|MessageChannel\s*\[" -C2

echo -e "\n=== Check for global. or window. patterns that might reference MessageChannel ==="
rg -n "global\.|window\." | head -20

echo -e "\n=== Check if setup.js is in test configuration ==="
find . -name "*.config.*" -o -name "*.conf.*" -o -name "jest.config.*" -o -name "vitest.config.*" 2>/dev/null | head -10
</parameter>

Repository: react-component/dialog

Length of output: 1936


🏁 Script executed:

#!/bin/bash
# Search for Worker usage or web worker patterns
echo "=== Worker usage ==="
rg -n "Worker|worker" -C2 --type=ts --type=tsx --type=js --type=jsx

echo -e "\n=== Check setupFilesAfterEnv to see what else is configured ==="
cat tests/setupFilesAfterEnv.ts 2>/dev/null || echo "File not found or cannot read"

Repository: react-component/dialog

Length of output: 232


Add global.MessageChannel assignment for consistency with other polyfills; skip extending API methods

The mock currently sets MessageChannel only on window, but other polyfills in the same file (requestAnimationFrame, cancelAnimationFrame) are assigned to both global and window. For consistency and to ensure broader compatibility in Node.js/Jest environment, add a global mapping:

 window.MessageChannel = class {
   port1;
   port2;
   constructor() {
@@
     this.port1 = port1;
     this.port2 = port2;
   }
-}
+};
+
+if (typeof global !== 'undefined') {
+  global.MessageChannel = window.MessageChannel;
+}

The codebase does not currently use addEventListener, removeEventListener, or close on MessageChannel instances, so expanding the mock API is unnecessary at this time. The basic postMessage and onmessage implementation is sufficient.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
window.MessageChannel = class {
port1;
port2;
constructor() {
const createPort = () => {
const port = {
onmessage: null,
postMessage: (message) => {
setTimeout(() => {
if (port._target && typeof port._target.onmessage === 'function') {
port._target.onmessage({ data: message });
}
}, 0);
},
_target: null,
};
return port;
};
const port1 = createPort();
const port2 = createPort();
port1._target = port2;
port2._target = port1;
this.port1 = port1;
this.port2 = port2;
}
}
window.MessageChannel = class {
port1;
port2;
constructor() {
const createPort = () => {
const port = {
onmessage: null,
postMessage: (message) => {
setTimeout(() => {
if (port._target && typeof port._target.onmessage === 'function') {
port._target.onmessage({ data: message });
}
}, 0);
},
_target: null,
};
return port;
};
const port1 = createPort();
const port2 = createPort();
port1._target = port2;
port2._target = port1;
this.port1 = port1;
this.port2 = port2;
}
};
if (typeof global !== 'undefined') {
global.MessageChannel = window.MessageChannel;
}
🤖 Prompt for AI Agents
In tests/setup.js around lines 28 to 54, the mock defines window.MessageChannel
but not global.MessageChannel; add an assignment so global.MessageChannel
references the same mock (e.g., global.MessageChannel = window.MessageChannel)
to match how other polyfills are exported, and do not extend the mock with
addEventListener/removeEventListener/close since those APIs are not used—keep
only postMessage and onmessage behavior.

Loading