Is this bug found yet?



  • Pre-initial case: Does a topic exist in which it can be asked if a bug is known?

    Initial case: Is it known that when adding an HTML comment in an edit, and doing nothing else, the comment is dropped (does not appear in the next view raw) ?



  • Have you tried waiting a few (30-ish) seconds and/or reloading?



  • Sounds like a variation of the bugs found in the thread over here



  • Really? Test...

    <!-- this comment was here frist --> <!-- edit: this comment was here second -->


  • I had not. And I did, by returning via back button to the relevant page and viewing raw on that render - at which point the comment did appear. So it can't be arsed to update the local model when that happens? Wow.



  • Okay, the second comment did not appear in the raw view after I edited, but after refresh it does.

    I'm guessing it only "refreshes" the post if the baked version changes (HTML comments are stripped out of the baked version).



  • Ah, did not expect it to be relevant that it was a second comment. It was also a second comment in my case. We have replication. I want to call this behavior a bug. Any second?



  • @Gribnit said:

    Ah, did not expect it to be relevant that it was a second comment.

    I don't think it's relevant. Let's try. No comment in this post!

    <!-- edit: nope, definitely no comment in this post. --> <!-- edit #2: okay, that one showed up --> <!-- edit #3: okay, what if I add a 3rd comment? -->


  • There is no comment in your post, when this post was initially created.



  • Okay, I initially wrote the post with no HTML comments; the first comment I edited to add actually did show up in the raw view. 2nd and 3rd comments did not show up in the raw view until after I refreshed the page.

    I'd say ... yes? probably a bug. However, HTML comments are stripped out of the post anyway, and isn't the Raw button something we added?



  • Comments are stripped from posts?<!-- Really? I am not sure how you are reading this then. Somehow it is getting there tho. I really hope you don't say, "Yes, they are"... or is the raw view an astonishingly unholy hack? -->



  • Yes, from the cooked version at least... if you highlight and view source, they're not there.

    <also broken HTML is stripped out>


  • @anotherusername said:

    isn't the Raw button something we added?

    The button to display it inline is ours, but the functionality is built-in.



  • This is another test. There's no comment in this post (yet).

    <!-- edit: now there is -->


  • @Gribnit said:

    I want to call this behavior a bug. Any second?

    Just don't call it late to dinner and I think we're all good here.



  • Okay, I've figured it out. It's not relevant that it was the 2nd comment; it just happens to be whether you've already viewed the Raw or not. After you've viewed the Raw at least once, if you then edit the post to add comments without adding anything that'll show up in the cooked version, the raw view doesn't show the edits unless you reload the page (or edit it again to add something that does change the cooked post).

    Basically, when you click Raw, it creates a <pre class="tdwtf-raw-area"> node after the <div class="cooked"> node. Neither of those nodes actually go away after that (unless the whole post gets unloaded as you scroll). After that, the raw button just toggles visibility to make one or the other visible. After you edit your post, the node containing the raw version only gets updated if the cooked version has changed. So comments, which are stripped from the cooked version, don't trigger that raw view to be updated.

    I don't think the bug is in Discourse itself, because the Edit box does show the correct raw version every time. The bug with the raw view is in the code that controls the Raw button not updating that DOM element when the raw version changed and the cooked version didn't.



  • Ah! ok good, so we still have support to address this.



  • Paging @Onyx, I guess.

    ISTR there was some reason for some caching at least, but that was a while ago.


  • :belt_onion:

    @Gribnit said:

    Ah! ok good, so we still have support to address this.

    :wave:

    Well, and Maciej, and whoever hacked on this later on. "View raw" is WTDWTF-ism, nowhere to be found in Discocore.

    @Maciejasjmj said:

    ISTR there was some reason for some caching at least, but that was a while ago.

    I think caching is something that was implemented later on. I always intended to do it but never had the time. But yeah, getting new raw every time you click the button was silly and slowed things down.

    Should be easy enough to fix. Will take a gander when I get a minute.



  • @Onyx said:

    Will take a gander when I get a minute.

    FTR, this is what we're currently using for Show Raw:

    // Show Raw button
    //http://what.thedailywtf.com/t/expanding-replies-hides-raw-button/7399/47?u=pjh
    (function(){
      //@Monarch at what.thedailywtf.com
      //Button is redelcared and sligthly modified due to new scope. it can be further simplified.
      Button = function(action, label, icon, opts) {
        this.action = action;
        this.label = label;
    
        if (typeof icon === "object") { this.opts = icon; } else { this.icon = icon;}
        this.opts = this.opts || opts || {};
    
        this.render = function (buffer){
            var opts = this.opts;
            buffer.push("<button title=\"" + this.label + "\"");
            if (opts.className) { buffer.push(" class=\"" + opts.className + "\""); }
            buffer.push(" data-action=\"" + this.action + "\">");
            if (this.icon) { buffer.push("<i class=\"fa fa-" + this.icon + "\"></i>"); }
            buffer.push("</button>");
        }
      };
    
    
    
        var PostMenuComponent = require('discourse/components/post-menu').default;
    
        PostMenuComponent.reopen({
          buttonForRaw:function(post){
              return new Button('raw', 'view raw post', 'code', {className: "raw-button", disabled: false});
          },
    
          clickRaw:function(post){
              var topicID = post.topic_id,
                  postID =  post.post_number,
                  postArea = $("article[data-post-id='"+post.id+"'] div.contents"),
                  $rawButton = $(this.element).find("button.raw-button"),
                  styles = [{backgroundColor: 'transparent', color: '#A7A7A7'},{backgroundColor: '#08C', color: '#FFF'}];
    
              if (postArea.find('.tdwtf-raw-area').length == 0){
                  var postArea_raw_content = $('<pre class="tdwtf-raw-area"></pre>'),
                      cooked = postArea.find('.cooked');
    
                      cooked.after(postArea_raw_content);
    
                  $.get('/raw/' + topicID + '/' + postID) .done(function (content) {
                      postArea_raw_content.addClass("active");
                      $rawButton.css(styles[1]);//active
                      postArea_raw_content.css({"white-space":"pre-wrap", 'border':'2px dashed #E7E7E7','padding':'3px'}) .text(content);
                      cooked.hide();
                  });
              } else {
                  var postArea_raw_content = postArea.find('.tdwtf-raw-area');
                  if ( !postArea_raw_content.hasClass("active") ){  //raw no active
                      postArea.find('.cooked').hide();  
                      postArea.find('.tdwtf-raw-area').show();
                      postArea_raw_content.addClass("active");
                      $rawButton.css(styles[1]);
                  } else{
                      postArea.find('.cooked').show();  
                      postArea.find('.tdwtf-raw-area').hide();
                      postArea_raw_content.removeClass("active");
                      $rawButton.css(styles[0]);
                  }
              }
          }
      });    
    })();
    


  • @Onyx said:

    Will take a gander


  • Winner of the 2016 Presidential Election

    Hoho, you goose, that's hillarious



  • Hmmm, so as long as the raw node exists it'll actually never update it... so the only reason it's updating the raw at all is if the edit function recreates the post, which apparently only happens when the cooked version changes.

    I don't see anything that changes if the cooked version changes... at this point I see the following options that may or may not be possible (I don't know enough about Discourse to know which):

    • link an event that updates the raw node to the save edit function
    • have an edit always update the post/remove the raw node, even if the cooked version isn't different
    • always update the raw node before it's shown; no caching
    • live with the bug

    The caching allows you to skip a GET request. Given that Discourse is firing off tons of requests anyway and I think normal use won't ever necessitate someone toggling the raw/cooked on and off very quickly, I wouldn't expect it to be too huge of a hit on performance to just update it every time it's shown. If you're worried about someone intentionally abusing it by spam-clicking the button, you could set a rate limiter like, say, 5 or 10 seconds, and not update the node unless it's older than that.


  • :belt_onion:

    @anotherusername said:

    link an event that updates the raw node to the save edit function

    Something already broke before because we did a similar thing. Not sure if raw button or something else, but it got broken by an update. I'd rather not poke into that.

    @anotherusername said:

    have an edit always update the post/remove the raw node, even if the cooked version isn't different
    always update the raw node before it's shown; no caching

    Which can be rather slow...

    I have an idea, actually. Hopefully I remember too look at this again when I come home. Need to test it first, there could be side-effects, depends on what exactly Discourse does to the DOM on post edit.



  • @Onyx said:

    depends on what exactly Discourse does to the DOM on post edit.

    I looked pre- and post-edit when I just added a comment to my post, and saw no discernible difference in the DOM (discounting "< 1m" changing to "1m"; that'll be changing regardless of edits).



  • To prevent repeated clicks of the raw button being slow, you could immediately show the cached raw, and send off a request in the background to fetch a fresh one?



  • @Onyx said:

    Hopefully I remember too look at this again

    I hope you remember, too.

    Filed under: Too easy


  • Winner of the 2016 Presidential Election

    On the bright side, he'll remember too look at it now


  • :belt_onion:

    Well, I did, but fever is a :barrier: to coding.

    Feeling a bit better today, will test it a bit later.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.