We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Quote from: captainstarbuck at Jan 01, 2013, 08:22 PM


    @frogabog - in the above case I always load the jQuery script but I only want to load the jQueryUI script when required. Your astute inquiry on that point is warranted, but in this case it logic is correct.

    Alright, just to make sure I'm on the same page...

    These are actually two different scripts. One is conditional and only in the chunk (we didn't see the chunk contents so I thought they were the same). You don't have to answer if I'm correct.

      Frogabog- MODX Websites in Portland Oregon
      "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
      Having server issues? These guys have MODX Hosting perfected - SkyToaster
    • I reported that some exception was causing my code to execute twice. This is yet another example of that. When the parser finds a :then without a :else (in this case) it must be throwing an error.
      Exceptions don't cause executing code twice. Period. And a :then without :else doesn't trigger an error, cause it is valid syntax. Without an else, it should simply echo the value of the base tag.

      What could be causing the issue has been touched on by others already:

      • The Mobile Detection plugin causes the second parse. I don't know its internals and it seems you have looked into it more than I have. But if disabling the mobile detection plugin causes the issue of double parsing to go away, then the answer is in that plugin. Basic logic: different inputs, different results, so look at the variation in inputs.
      • Tags are duplicated, for example calling [[*content]] in 2 locations like the header and the regular content location. Cached tags should be executed just once (they're cached as soon as they're called iirc), but uncached tags would be executed independently twice.

      The issue with the output filters you describing, seem to be related to how nested tags work. See https://www.markhamstra.com/modx-blog/2011/11/nested-caching-in-modx-revolution/ for some information, but I'm thinking that the occurrence of `:, even in your "malicious" attempt, is messing with some output filters you are using "upstream" in the parsing. Say you have this somewhere:

      [[*id:neq=`1`:then=`[[$headerchunk]]`]]

      with the headerchunk contents being:
      <!-- [x [x * using_accordion :is=`yes`:then=`[x [x $ accordion_script ] x]`] x] -->

      that will evaluate to:
      [[*id:neq=`1`:then=`<!-- [x [x * using_accordion :is=`yes`:then=`[x [x $ accordion_script ] x]`] x] -->`]]

      The stray ` characters could definitely mess something up unexpectedly there.

      If you would use the recommended way of commenting out tags:
      [[-*using_accordion:is=`yes`:then=`[[$accordion_script]]`]]

      the entire tag would be ignored.

      Also related reading regarding performance: http://modx.com/blog/2012/09/14/tags-as-the-result-or-how-conditionals-are-like-mosquitoes/ [ed. note: markh last edited this post 11 years, 4 months ago.]
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 42393
        • 143 Posts
        Quote from: markh at Jan 01, 2013, 10:42 PM
        Exceptions don't cause executing code twice. Period.
        Well, I will accept that, but will add that I have two 100% reproducible ways of proving that "some kind of error" causes the life cycle to execute twice, and in one case trapping exceptions stopped that from happening. I disabled that MobileDetection plugin, even after verifying that it doesn't repost. The problem wasn't with that code but that the code was being executed twice. Later I wrote my own tiny snippet which was also executed twice. That code also does not in any way load itself or external resources. But I believe you have provided part of the solution here...
        Quote from: markh at Jan 01, 2013, 10:42 PM
        The issue with the output filters you describing, seem to be related to how nested tags work. ...
        [[*id:neq=`1`:then=`<!-- [x [x * using_accordion :is=`yes`:then=`[x [x $ accordion_script ] x]`] x] -->`]]
        The stray ` characters could definitely mess something up unexpectedly there. If you would use the recommended way of commenting out tags:
        [[-*using_accordion:is=`yes`:then=`[[$accordion_script]]`]]
        the entire tag would be ignored.
        Now THAT is good info. I would bet that the nested tags caused the errors. If that's recognized behavior then the case is closed, mea culpa, I'll know to look out for this. I'm sorry but since I'm new at this I have not yet stumbled upon documentation on issues with nested tags. Nor do I recall seeing that [[-]] syntax for disabling a tag.

        I said above that I believe you have identified "part" of issue, because I have verified several times in my diagnostic that I am not repeating tag calls, and yet I had both a plugin and a snippet executing twice. I'll accept that the faulty tag construction caused that - I'm just hoping you will accept that this GIGO condition, where a poorly constructed set of nested tags can cause resources to reload. I'm not asking for a fix, just hoping for acknowledgment that this condition could exist.
        Quote from: markh at Jan 01, 2013, 10:42 PM
        Also related reading regarding performance: http://modx.com/blog/2012/09/14/tags-as-the-result-or-how-conditionals-are-like-mosquitoes/
        I've only skimmed that so far but I know I've already started coding against Jason's advice and I will immediately correct this bad habit. I'm sure it's been discussed before, but in the name of performance it would be good if then/else clauses weren't processed until needed.

        Thank you Very much, Mark. I will report back here later after I have changed everything as indicated. It will take several days.
          Loved ModX when I was using it a few years ago. Shifted to WordPress, sorry. Thanks, all.
        • Yes, some sort of tag soup could cause issues, often on the surface unpredictable ones too.

          ...where a poorly constructed set of nested tags can cause resources to reload. I'm not asking for a fix, just hoping for acknowledgment that this condition could exist....
          The word "reload" there is interesting; are you actually seeing a page reload (via the dev tools network tab in your browser)? I thought you were saying a single page load was triggering a snippet twice.
            Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

            Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
            • 42393
            • 143 Posts
            Semantics are important. No, this wasn't a page reload. (And I understand that 3 pages of discussion can confuse the situation.) It's explained better in the first post for this thread.

            If you go back there you can probably understand my confusion about how a simple random error triggered that plugin to re-execute while still in the same system event. Note that there is one header for the event and 3 errors flagged. I believe a "reload", whether triggered by browser or life cycle, would cause output in the log show the event and an error, then the event again and another error.

            I'm sorry that we're on different levels here - you know how it works but can't see this happening live (at the moment) and I can see it and only guess at what's happening to help trigger your thoughts. smiley

            I think we're agreed that "tag soup" in any environment can cause all sorts of random effects in a system. I'm OK with that conclusion.
              Loved ModX when I was using it a few years ago. Shifted to WordPress, sorry. Thanks, all.
            • In your case, the complete nested tag appearing in the conditional filter was always executed once, regardless of the condition being evaluated.
              • And this only confirms the view I've had of phx when it was developed as a plugin for Evo and the built-in version for Revo. It's an extra layer of complexity that can almost always be handled in some other way; in this case Bruno's suggestion here would be a much better solution to the problem.

                http://forums.modx.com/thread/81363/snippet-executes-twice---seems-to-be-revo-bug?page=2#dis-post-448856
                  Studying MODX in the desert - http://sottwell.com
                  Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                  Join the Slack Community - http://modx.org
                • Quote from: sottwell at Jan 02, 2013, 04:18 PM
                  And this only confirms the view I've had of phx when it was developed as a plugin for Evo and the built-in version for Revo. It's an extra layer of complexity that can almost always be handled in some other way; in this case Bruno's suggestion here would be a much better solution to the problem.

                  http://forums.modx.com/thread/81363/snippet-executes-twice---seems-to-be-revo-bug?page=2#dis-post-448856
                  Agreed. If you use it as a text processing engine to construct tags, the conditional filters can be very useful. Just don't embed tags in conditional paths and the problem can be avoided.