-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change
writeClipboardText
/readClipboardText
clipboard fallback to…
… in-memory (#2076) Using the local storage as a fallback caused issues when writing clipboard contents larger than 5MB. Changing the fallback to in-memory resolves the issue. --- <!-- Everything below this line will be removed from the commit message when the PR is merged --> ## PR Checklist - [x] Verify if the change requires a changeset. See [CONTRIBUTING.md](https://github.com/vivid-planet/comet/blob/HEAD/CONTRIBUTING.md) - [x] Link to the respective task if one exists: COM-744
- Loading branch information
1 parent
9732556
commit 8e3dec5
Showing
4 changed files
with
64 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
"@comet/admin": minor | ||
--- | ||
|
||
Change `writeClipboardText`/`readClipboardText` clipboard fallback to in-memory | ||
|
||
Using the local storage as a fallback caused issues when writing clipboard contents larger than 5MB. | ||
Changing the fallback to in-memory resolves the issue. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Alert, readClipboardText, writeClipboardText } from "@comet/admin"; | ||
import { Button, Grid } from "@mui/material"; | ||
import { storiesOf } from "@storybook/react"; | ||
import React from "react"; | ||
|
||
storiesOf("@comet/admin/clipboard", module).add("Clipboard fallback size limit", function () { | ||
const writtenClipboardContent = "a".repeat(1024 * 1024 * 10); // 10MB | ||
const [readClipboardContent, setReadClipboardContent] = React.useState<string | undefined>(); | ||
|
||
return ( | ||
<Grid container spacing={2}> | ||
<Grid item xs={12}> | ||
<Alert severity="info">To test this story, either a) disallow clipboard access in your browser, or b) try it in Firefox.</Alert> | ||
</Grid> | ||
<Grid item> | ||
<Button | ||
variant="outlined" | ||
onClick={() => { | ||
writeClipboardText(writtenClipboardContent); | ||
}} | ||
> | ||
Write clipboard | ||
</Button> | ||
</Grid> | ||
<Grid item> | ||
<Button | ||
variant="outlined" | ||
onClick={async () => { | ||
setReadClipboardContent(await readClipboardText()); | ||
}} | ||
> | ||
Read clipboard | ||
</Button> | ||
</Grid> | ||
{readClipboardContent && ( | ||
<Grid item xs={12}> | ||
{writtenClipboardContent === readClipboardContent ? ( | ||
<Alert severity="success">Read clipboard content matches written clipboard content.</Alert> | ||
) : ( | ||
<Alert severity="error">Read clipboard content does not match written clipboard content.</Alert> | ||
)} | ||
</Grid> | ||
)} | ||
</Grid> | ||
); | ||
}); |