Page MenuHomePhorge

RemarkupMetadata.js - Error: Empty ID passed to JX.$()!
Closed, ResolvedPublic

Description

Probably after D25052: Add and use new RemarkupMetadata class, sometime I get this JavaScript error in the console:

Error: Empty ID passed to JX.$()!
    $E        core.pkg.js:27
    $         core.pkg.js:3201
    construct RemarkupMetadata.js:18

The problem seems caused by RemarkupMetadata.js on line 18:

https://we.phorge.it/source/phorge/browse/master/webroot/rsrc/js/core/RemarkupMetadata.js;90f9da643d1622bcfff3a8903159aeefd1b42520$18

I report it here for historical reasons:

/**
 * @requires javelin-install
 *           javelin-dom
 *           javelin-json
 * @provides phabricator-remarkup-metadata
 * @javelin
 */

JX.install('RemarkupMetadata', {

  construct: function(metadataValue, metadataID) {
    if (JX.RemarkupMetadata._metadataValue == null) {
      JX.RemarkupMetadata._metadataValue = {};
    }
    if (!JX.RemarkupMetadata._metadataValue.hasOwnProperty(metadataID)) {
      JX.RemarkupMetadata._metadataValue[metadataID] = metadataValue;
    }
    this._metadataNode = JX.$(metadataID); // ← problematic line
    this._metadataID = metadataID;
  },

That is called from behavior-drag-and-drop-textarea.js line 30:

https://we.phorge.it/source/phorge/browse/master/webroot/rsrc/js/core/behavior-drag-and-drop-textarea.js;90f9da643d1622bcfff3a8903159aeefd1b42520$30-31

JX.behavior('aphront-drag-and-drop-textarea', function(config) {

  var target = JX.$(config.target);

  if (JX.PhabricatorDragAndDropFileUpload.isSupported()) {
    var drop = new JX.PhabricatorDragAndDropFileUpload(target)
      .setURI(config.uri)
      .setChunkThreshold(config.chunkThreshold);

    drop.listen('didBeginDrag', function() {
      JX.DOM.alterClass(target, config.activatedClass, true);
    });

    drop.listen('didEndDrag', function() {
      JX.DOM.alterClass(target, config.activatedClass, false);
    });

    drop.listen('didUpload', function(file) {
      JX.TextAreaUtils.insertFileReference(target, file);

// TODO: ↓ probably this line needs a NULL check on config.remarkupMetadataID
      var metadata = new JX.RemarkupMetadata(config.remarkupMetadataValue,
        config.remarkupMetadataID);

Steps to reproduce

  1. Open the Persistent Chat
  2. Drag & Drop a file there