Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-84076

core/templates JS module alters template context object

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 4.4.6, 4.5.2, 5.0
    • JavaScript

      A template context object inside a JS module will be altered by a call to the core/templates render methods. The following code will output not just "foo": "bar" on the browser console, but also all the mustache helper methods and attributes even though the rendering will be called afterwards:

      const context = {
        "foo": "bar"
      };
      console.log(context);
      const {html, js} = await Templates.renderForPromise('local_myplugin/mytemplate', context); 

      This should be avoided because developers are not expecting the objects they are passing to the render function to be altered in general. Especially the fact that the object is being altered before the render function is being called due to the async/await notation is very confusing.

      This might be regression caused by MDL-78266 but I didn't have the time to verify, so I did not add an issue reference.

            phmemmel PhMemmel
            phmemmel PhMemmel
            Meirza Meirza
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 4 hours, 25 minutes
                4h 25m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.