Show users exactly what the AI changed before they accept it A developer tutorial published in the newsletter outlines a roughly 30-line JavaScript approach for showing users a word-level diff of AI-suggested text edits before they accept them, using a longest-common-subsequence comparison and native `` and `` elements. The tutorial argues that without such a preview, users can ship AI rewrites that silently change facts — its example is a landing page that says $39 while checkout charges $49 — and it recommends rendering model output with `textContent` rather than `innerHTML` because the suggestion is untrusted. The technique requires no library and lets users edit the suggestion while the diff updates. Show users exactly what the AI changed before they accept it Creem.io Merchant of record payments for SaaS and digital products, handling checkout, subscriptions, taxes, invoices, and global payment operations. Sponsor this newsletter · reach 9,500+ active developers https://markodenic.tech/sponsorship/ You add an “Improve with AI” button to your editor. The user clicks it, a polished paragraph comes back, and it replaces theirs. It reads well, so they ship it. Two days later a customer asks why the landing page says $39 when checkout charges $49. The AI “improved” the price too. The user didn’t miss it because they were careless. Nobody re-reads a whole paragraph hunting for a changed word. Code editors solved this decades ago with a diff: removed words struck through in red, added words in green. Your text fields can do the same in about 30 lines, no library. The fix Compare the two texts word by word and keep what they share: js function diffWords before, after { const a = before.match /\S+\s /g ?? ; const b = after.match /\S+\s /g ?? ; const lcs = a.map = new Array b.length + 1 .fill 0 ; lcs.push new Array b.length + 1 .fill 0 ; for let i = a.length - 1; i = 0; i-- { for let j = b.length - 1; j = 0; j-- { lcs i j = a i === b j ? lcs i + 1 j + 1 + 1 : Math.max lcs i + 1 j , lcs i j + 1 ; } } const parts = ; const push = type, text = { const last = parts.at -1 ; if last?.type === type last.text += text; else parts.push { type, text } ; }; let i = 0, j = 0; while i < a.length || j < b.length { if a i === b j { push 'same', a i ; i++; j++; } else if j === b.length || i < a.length && lcs i + 1 j = lcs i j + 1 push 'del', a i++ ; else push 'ins', b j++ ; } return parts; } Then render it with real