Project

General

Profile

Actions

Patch #43259

open

Convert jstoolbar to ES modules and class syntax.

Added by Takashi Kato 6 months ago. Updated 16 days ago.

Status:
New
Priority:
Normal
Category:
Code cleanup/refactoring
Target version:

Description

This patch is based on a branch from #43165, with minor modifications.

  • Converting the entire library to ES modules eliminates the risk of variable name collisions.
  • Refactored jstoolbar from the old prototype-based syntax to a more readable class syntax.
  • Switched DOM element creation from JavaScript to ERB, which makes preparing and cloning DOM elements easier by using the <template> element.
  • Moved all jstoolbar locales to config/locales to simplify i18n. * Added the missing tasklist locale for both ja and en.
  • Integrated the list-autofill controller into jstoolbar as both controllers are used in the same places.

Applying this patch along with #42521 enables the implementation of #40310.

This patch can be applied to r24014


Files

0001-Convert-jstoolbar-to-ES-Module.patch (227 KB) 0001-Convert-jstoolbar-to-ES-Module.patch Takashi Kato, 2025-09-28 06:01
0001-wip.patch (44.8 KB) 0001-wip.patch Marius BĂLTEANU, 2026-02-21 19:43
0001-jstoolbar-to-stimulus.patch (46.9 KB) 0001-jstoolbar-to-stimulus.patch Takashi Kato, 2026-03-01 03:14

Related issues

Related to Redmine - Patch #37559: Use meta element instead of javascript objectNewMarius BĂLTEANUActions
Actions #1

Updated by Marius BĂLTEANU 6 months ago

  • Assignee set to Marius BĂLTEANU
  • Target version set to 7.0.0

I'm assigning this 7.0.0 in order to review the changes.

Actions #2

Updated by Marius BĂLTEANU 23 days ago

  • File 0001-wip.patch added

Takashi Kato, I started to work on rewriting the toolbar in order to render most of the elements on the backend and connect to Stimulus JS for the actions. Here is a prof of concept only for testing purposes, it still need some work.

Any feedback is welcome!

Actions #3

Updated by Marius BĂLTEANU 23 days ago

  • File deleted (0001-wip.patch)
Actions #5

Updated by Marius BĂLTEANU 23 days ago

  • Related to Patch #37559: Use meta element instead of javascript object added
Actions #6

Updated by Takashi Kato 16 days ago

I applied the patch. I think the new toolbar design is simpler and better than before.

  • Toolbar generation is now separated into its own class
    • This has the benefit of allowing shorter method names
    • Memoization speeds up rendering on subsequent runs.
  • Key binding configuration has been moved from JavaScript to the data-action attribute in Stimulus.
  • Added configuration for a hotkey to toggle the preview.
Actions #7

Updated by Takashi Kato 16 days ago

I confirmed that subsequent renderings within the same request become faster with code like the following.

require 'test_helper'
require 'benchmark/ips'

class ViewPerformanceTest < ActionDispatch::IntegrationTest
  def setup
    @controller = ApplicationController.new
    @controller.request = ActionDispatch::TestRequest.create
    @view_context = @controller.view_context
  end

  def test_view_benchmarks
    puts "\n--- Benchmarking Render Methods ---" 

    Benchmark.ips do |x|
      x.report('Helper (Cold Start)') do
        controller = ApplicationController.new
        controller.request = ActionDispatch::TestRequest.create
        view_context = controller.view_context
        view_context.wikitoolbar(preview_url: "/users/1"){'<textarea></textarea>'}
      end

      # Execute it once beforehand to memoize it.
      @view_context.wikitoolbar(preview_url: "/users/1"){'<textarea></textarea>'}

      x.report("Helper (Memoized)") do
        @view_context.wikitoolbar(preview_url: "/users/1"){'<textarea></textarea>'}
      end

      x.compare!
    end
  end
end
--- Benchmarking Render Methods ---
ruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +PRISM [x86_64-linux]
Warming up --------------------------------------
 Helper (Cold Start)    40.000 i/100ms
   Helper (Memoized)   439.000 i/100ms
Calculating -------------------------------------
 Helper (Cold Start)    401.374 (±12.7%) i/s    (2.49 ms/i) -      2.000k in   5.073074s
   Helper (Memoized)      5.138k (±11.7%) i/s  (194.61 μs/i) -     25.462k in   5.033269s

Comparison:
   Helper (Memoized):     5138.4 i/s
 Helper (Cold Start):      401.4 i/s - 12.80x  slower

Actions

Also available in: Atom PDF