The html.ts file runs twice in my moovweb project

I had a problem when the html.ts file is run twice on certain pages, even if AJAX is disabled in the browser. This does not seem to be a problem with matching, as it does this behavior, even if I comment on all the comparisons. The page looks good in the Chrome browser.

+4
source share
2 answers

If nothing is pasted into an AJAX page or something else, this is probably due to poorly formed html. If there is something in the source outside the <head> , <body> or <html> source, Gokogiri wraps the highlighted markup in a separate <html> . Then, since there are two opening and closing <html> tags, html.ts will be executed twice. The solution is to catch the incoming page before we tell Gokogiri what to do with it, and fix the broken html, making sure everything is wrapped with a <body> .

In the /main.ts scripts in the project folder after

 match($content_type) { with(/html/) { 

add this which removes the </body> and </html> tags and adds them to the end:

  # wrap markup that is outside the body so tritium doesn't get applied twice replace(/\<\/body\>/,"") replace(/\<\/html\>/,"") append("</body> </html>") 

This should ensure that there is only one opening of the closing <html> tag that is passed to Gokogiri and that html.ts is run only once, as we want!

The reason the source probably looks good in Chrome is because when the Tritium code manipulates the page, it moves things from both <html> tags to the first, and when Chrome receives the page, it will erase the second, empty <html> .

+6
source

It may also be that there are two <html> tags to get you started! And they are selected in your html.ts file. Since the html.ts file starts with the $("/html") { selector, if so, there are two <html> tags, then the code will run twice.

Check iframes on the page, which may be the reason for this!

+2
source

All Articles