INC-4821: Checkout latency
Resolvedp95 latency rose to 2.4 s after the cart-v3 rollout. Rolled back at 14:05; error budget used: 18%. Details in the postmortem.
| Metric | Before | Peak |
|---|---|---|
| p95 latency | 310 ms | 2,400 ms |
| Error rate | 0.02% | 1.3% |
Copy a card, a note, a report or a table from your app and paste it into Gmail, Outlook
or Google Docs, and it usually comes out wrong. The classes and stylesheets it depended on
don’t travel. Modern CSS colours like Tailwind’s oklch() mean nothing to mail clients.
Light text from a dark theme turns invisible on a white page. Relative links and images
break. And the browser’s own copy fills the paste with layout CSS and page chrome.
react-smart-copy/rich copies what the reader sees, in HTML that every destination keeps.
p95 latency rose to 2.4 s after the cart-v3 rollout. Rolled back at 14:05; error budget used: 18%. Details in the postmortem.
| Metric | Before | Peak |
|---|---|---|
| p95 latency | 310 ms | 2,400 ms |
| Error rate | 0.02% | 1.3% |
Press Copy for email to see it.
Select any part of this paragraph and press Ctrl + C or ⌘ + C. The bold, the emphasis and this link paste as they look, in colours every mail client understands.
Nothing copied from it yet.
Copy a few paragraphs from Google Docs, Word, Gmail or a web page and paste them below. Headings, lists, tables, links and formatting stay; fonts, colours, Office markup and anything unsafe go.
Nothing pasted yet.
Cleaned HTML
Paste to see it.
richPayload reads the computed styles, writes them inline, turns every colour into hex, and
leaves out scripts, controls, hidden content and tracking images. Links and images become absolute.
In dark mode, the card keeps its own dark background, so its light text stays readable. The paragraph
below has no background of its own: on a white email its light text would vanish, so
colors: "readable" leaves it to the destination's colour.
import { richPayload, richTransform } from 'react-smart-copy/rich';
copy(() => richPayload(cardRef.current));
useCopyInterceptor(articleRef, { transform: richTransform() });
Pasting in is pasteAsRich for a contenteditable element, or
pasteToRich in your editor's paste hook. Formatting set by CSS becomes tags, Word's list
paragraphs become lists, and every style, class and id goes.
<div contentEditable onPaste={pasteAsRich} />
transformPastedHTML: (html) => pasteToRich({ html })?.html ?? html
import { useCopy, useCopyInterceptor } from "react-smart-copy";import { richPayload, richTransform } from "react-smart-copy/rich";
const { copy } = useCopy();<button onClick={() => copy(() => richPayload(cardRef.current))}>Copy for email</button>
// Ctrl/⌘+C of any selection inside the article is portable too:const { ref: articleRef } = useCopyInterceptor({ transform: richTransform() });<article ref={articleRef}>…</article>What it writes:
data-copy-ignore or aria-hidden. Every
attribute is checked against an allowlist.flex,
grid, position) is never copied, because no destination keeps it.oklch(), color(),
rgb(… / 50%) or a CSS variable, becomes an opaque hex value drawn over its background.
With colors: "readable" (the default), text that would fall under 3:1 contrast where
it lands, like light text from a dark theme, takes the destination’s own colour.
"keep" copies every colour, and "none" copies none.https:,
http:, mailto: and tel: (protocols changes this). Images keep https: and http:
sources with their displayed size as attributes, which Outlook needs. data: images
need dataImages: true, because many mail clients block them. images: "alt" writes
their alt text instead, and images: "drop" leaves them out.text: (root) => htmlToMarkdown(root).markdown
gives Markdown instead.prepareRich(source, options) returns { html, text, removed, truncated }. removed
lists what was left out and why (unsafe-element, unsafe-link, unreadable-color,
hidden, …), for logs and audits. The source can be an element, a selection Range, a
fragment or HTML text. HTML text is parsed inertly, and only its style attributes are
read. The output is built in a separate, inert document, so nothing is inserted into your
page and no image loads while it is prepared. maxElements (10,000) and maxLength
(about 1 MB) bound the work.
The output is property-tested against hostile HTML. DOMPurify finds nothing to remove from it, and running the output through again changes nothing. In Chromium, Firefox and WebKit, the computed styles are checked end to end.
| Option | Default | Notes |
|---|---|---|
colors |
"readable" |
"keep", "none" |
background |
"#ffffff" |
where it is pasted, for readability |
images / dataImages |
"keep" / false |
"alt", "drop" |
styles |
"computed" on the page, "inline" otherwise |
"none" |
ignore |
none | a CSS selector to leave out |
base / protocols |
the page / https:, http:, mailto:, tel: |
links |
maxElements / maxLength |
10,000 / 1,000,000 | then truncated |
text |
readable plain text | your own, such as Markdown |
The other way round: paste from Google Docs, Word, Outlook, Gmail or a web page into your
editor, and get the content without the mess. Docs marks bold with font-weight: 700 on
spans inside a <b> that isn’t bold. Word writes lists as paragraphs with mso-list
styles and hides the bullets in spans. Mail wraps everything in layout tables. And every
source brings its fonts, colours and classes, which fight your editor’s look.
pasteToRich turns all of it into clean, semantic HTML.
import { pasteAsRich, pasteToRich } from "react-smart-copy/rich";
// A contenteditable element: inserted with undo intact<div contentEditable onPaste={pasteAsRich} />
// TipTap / ProseMirror: clean it before the editor parses ituseEditor({ editorProps: { transformPastedHTML: (html) => pasteToRich({ html })?.html ?? html } });
// Lexical: clean, then let Lexical import iteditor.registerCommand(PASTE_COMMAND, (event) => { const pasted = pasteToRich({ html: event.clipboardData?.getData("text/html") }); if (pasted?.source !== "html") return false; editor.update(() => $insertNodes($generateNodesFromDOM(editor, new DOMParser().parseFromString(pasted.html, "text/html")))); return true;}, COMMAND_PRIORITY_HIGH);
// A comment box: only what its toolbar has, and all of the textpasteToRich(result, { formats: ["bold", "italic", "link", "list"] });What it writes:
<strong>, <em>, <u>, <s>, <code>, <sup> and <sub>.
Formatting set by CSS becomes these tags, and CSS wins over tags, as in the browser.
Every style, class and id is left out, so pasted content takes your editor’s look.<pre> keeps its
lines and indentation.prepareRich: allowlisted elements and attributes, links
and images with absolute, scheme-checked URLs. Google and Outlook Safe Links redirects
are unwrapped to their destination. Relative links have no address to resolve against,
so they keep their text, unless you give base. removed reports scripts, embeds, unsafe
links and images left out; it doesn’t report what every clipboard document carries (its
head, Office markup).formats limits the output to what your editor holds. Nothing is lost: a heading
becomes a bold paragraph, a list item a paragraph after its marker, a table its cells, a
code block its lines, an image its alt text.pasteToRich(source, options) takes { html, text } (a PasteResult from usePaste
fits) and returns { html, text, removed, truncated, source }, or null when there is
nothing to paste. Plain text becomes paragraphs and line breaks (source: "text"), and
needs no DOM, so it works on a server too. pasteAsRich(event, options) handles a paste
into a contenteditable element and leaves plain-text pastes to the browser; onPaste
sees the result first, and returning false lets you insert it yourself. maxNodes
(200,000), maxElements and maxLength bound the work, and HTML is read up to 16 MiB.
It is property-tested against generated Docs, Word, mail and hostile HTML. It writes only allowlisted markup, and DOMPurify finds nothing to remove. Every visible character is kept, with the bold, italic, underline, strikethrough, code, superscript and subscript it showed. And cleaning twice changes nothing.
A note for sites that collect Content Security Policy reports. Pasted HTML is parsed in an
inert document, where scripts and handlers never run. Since Chromium 156, though, parsing an
inline handler there (<img onerror=…> from a web page) under a policy that blocks inline
handlers sends a script-src-attr report, whose target is the document rather than an element.
Every HTML sanitizer that parses in the browser triggers it, and nothing is blocked that would
have run (w3c/webappsec-csp#824).