I am having issues with (setf (user-styles user-script-mode) new-styles) not removing the old styles

I am having issues with (setf (user-styles user-script-mode) new-styles) not removing the old styles.
The new styles seem to be appended on top of the old ones.

E.g. loading these styles in sequence will change the color to black, then red, then red again:

body { background-color: black !important; }
body { background-color: red !important; }
body { }

The “Inspect Element” view shows styles being appended on top of, and overriding, each other.

The code I am using:
(btw if there is an existing/better way, I would love to use that instead)
(I am also mostly unfamiliar with CL and entirely unfamiliar with CLOS, so there might be something obviously wrong that I am missing ._.)

(defvar *user-styles-dir* (make-instance 'nyxt:config-directory-file :base-path #p"user-styles/"))

(nyxt:define-command reload-user-styles (&optional (buffer (current-buffer)))
  ;; (log:warn "user styles at ~a" (files:expand *user-styles-dir*))
  (enable-modes :modes 'nyxt/mode/user-script:user-script-mode :buffers buffer)
  (setf (nyxt/mode/user-script:user-styles (nyxt:find-submode 'nyxt/mode/user-script:user-script-mode buffer))
        (loop for path in (uiop:directory-files (files:expand *user-styles-dir*))
              collect (make-instance 'nyxt/mode/user-script:user-style
                                     :base-path path))))

EDIT: by “loading these styles in sequence” I mean changing the css file and invoking the reload-user-styles function on the same buffer.

Some more clarification:

  • Do you reload the buffer after setting new styles?
  • Does toggling user-script-mode change anything?

All in all, this looks like a bug that’s better reported on Github :thinking: