From fd4d5bfbd1fcc63c4eec86e3493df70be51116d9 Mon Sep 17 00:00:00 2001 From: Erik Michelson Date: Tue, 10 Feb 2026 15:09:28 +0100 Subject: [PATCH] fix(editor): always use random hex colors chance.color() can output all valid CSS values for colors, including rgba() syntax and predefined color names. Due to the usage of hex2rgb and other methods, this can break the editor. This commit ensures that all randomly generated colors are specified in hex format. Signed-off-by: Erik Michelson --- lib/letter-avatars.js | 1 + lib/realtime.js | 4 ++-- public/docs/release-notes.md | 5 +++++ public/js/index.js | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/letter-avatars.js b/lib/letter-avatars.js index 5f489248..235baf8b 100644 --- a/lib/letter-avatars.js +++ b/lib/letter-avatars.js @@ -8,6 +8,7 @@ const config = require('./config') exports.generateAvatar = function (name) { // use darker colors for better contrast const color = new Chance(name).color({ + format: 'hex', max_red: 150, max_green: 150, max_blue: 150 diff --git a/lib/realtime.js b/lib/realtime.js index 9a28b8e5..ac727180 100644 --- a/lib/realtime.js +++ b/lib/realtime.js @@ -710,7 +710,7 @@ function connection (socket) { // initialize user data // random color - let color = chance.color() + let color = chance.color({ format: 'hex' }) // make sure color not duplicated or reach max random count if (notes[noteId]) { let randomcount = 0 @@ -723,7 +723,7 @@ function connection (socket) { } }) if (found) { - color = chance.color() + color = chance.color({ format: 'hex' }) randomcount++ } } while (found && randomcount < maxrandomcount) diff --git a/public/docs/release-notes.md b/public/docs/release-notes.md index 87b87cf5..ec231601 100644 --- a/public/docs/release-notes.md +++ b/public/docs/release-notes.md @@ -1,5 +1,10 @@ # Release Notes +## Unreleased + +### Bugfixes +- Random colors for user's cursors and selections are now always in hex format to avoid conversion errors + ## 1.10.6 2026-02-04 ### Security fixes diff --git a/public/js/index.js b/public/js/index.js index 22f7ab9d..9e37e1fd 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -427,7 +427,7 @@ const supportExtraTags = [ text: '[random color tag]', search: '[]', command: function () { - const color = chance().color() + const color = chance().color({ format: 'hex' }) return '[color=' + color + ']' } }