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

Normalise component names in JS string functions

XMLWordPrintable

    • MOODLE_39_STABLE
    • MOODLE_38_STABLE
    • MDL-68528-master
    • Hide
      1. Place the attached foo.mustache into lib/templates
      2. Ensure that cachejs is enabled (e.g. mdk run undev)
      3. Purge caches
      4. Open site home page
      5. Open developer tools
      6. Open Console and run:

        require(['core/str'], S => {S.get_string('abouttobeinstalled', 'core'); S.get_string('actionchoice', 'core'); S.get_string('adminhelpconfiguration', 'core');});
        

      7. Open the network tab and clear it
      8. Switch back to Console and run:

        require(['core/templates'], T => T.render('core/foo', {}));
        

      9. Switch back to network tab
        1. Confirm that there are no calls to fetch any strings (e.g. "service-nologin.php?info=core_get_string...")
          Note: You may have to investigate the requests to confirm this
          Note: There will be some calls to fetch things like the icon system.
          For master this will be improved in MDL-68524
      Show
      Place the attached foo.mustache into lib/templates Ensure that cachejs is enabled (e.g. mdk run undev ) Purge caches Open site home page Open developer tools Open Console and run: require(['core/str'], S => {S.get_string('abouttobeinstalled', 'core'); S.get_string('actionchoice', 'core'); S.get_string('adminhelpconfiguration', 'core');}); Open the network tab and clear it Switch back to Console and run: require(['core/templates'], T => T.render('core/foo', {})); Switch back to network tab Confirm that there are no calls to fetch any strings (e.g. " service-nologin.php?info=core_get_string... ") Note: You may have to investigate the requests to confirm this Note: There will be some calls to fetch things like the icon system. For master this will be improved in MDL-68524

      Our JS String function component normalisation does not match what we do in PHP.

      In PHP we normalise both "moodle" and an empty string to "core". In JS we do neither.

      For the most part this is okay - we have never done this, however we also do not do this for templates.

      If you have a template which contains either of the old values, then the template stringHelper function sees it as a required string, it is not normalised in the core/str module, and then we perform a WS call to fetch it. The WS call happens in PHP land where the normalisation does happen.

      This leads to a performance issue as strings will be fetched multiple times if the inconsistent components are used.

      We have two options:

      1. normalise the string in core/str; or
      2. normalise in the template stringHelper.

      If we normalise in the string module then this will mean that we have the same API in both PHP and JavaScript, but we will essentially be allowing a deprecated component name to be used in JavaScript where it was never previously allowed.

      If we normalise in the template module then we will solve the function for templates, but have an inconsistent API between JS and PHP.

      Since the empty string is still typically seen in a number of parts of Moodle and traditionally accepted, we could have a combined approach:

      1. normalise both moodle and empty string to core in the template module's stringHelper; and
      2. normalise an empty string to core in the string module.

            dobedobedoh Andrew Lyons
            dobedobedoh Andrew Lyons
            Simey Lameze Simey Lameze
            Jun Pataleta Jun Pataleta
            Janelle Barcega Janelle Barcega
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 3 hours, 15 minutes
                3h 15m

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