Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

html.ts file is running twice in my moovweb project

Tags:

ajax

moovweb

I'm running into an issue where the html.ts file is being run twice on certain pages, even with AJAX turned off in the browser. It does not seem to be a mapping issue, as it does this behavior even if I comment out all the mappings. The page looks fine in the Chrome browser.

like image 387
naryasece Avatar asked Feb 16 '23 19:02

naryasece


2 Answers

If nothing is being inserted into the page by AJAX or anything else, then this is probably due to badly formed html. If there is anything in the source outside of <head>, <body> or <html>, Gokogiri wraps the outlying markup in a separate <html> tag. Then since there are two opening and closing <html> tags, html.ts will be run twice. The solution is to catch the incoming page before we tell Gokogiri what to do with it, and fix the broken html by making sure everything is wrapped in the <body> tag.

In scripts/main.ts in your project folder, after

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

add this, which removes the </body> and </html> tags and appends 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>")

That should ensure there is only one opening an closing <html> tag that gets passed to Gokogiri and that html.ts is only run once as we want it to!

The reason the source probably looks okay in Chrome because when the Tritium code is manipulating the page, it moves stuff from both <html> tags into the first one, and when Chrome receives the page, it will wipe the second, empty <html> tag.

like image 141
wonj Avatar answered Feb 19 '23 08:02

wonj


It could also be that there are two <html> tags to begin with! And those are being selected in your html.ts file. Since the html.ts file begins with the selector $("/html") {, if this is the case and there are two <html> tags then the code will be run twice.

Check for iframes on the page that could be causing this!

like image 23
nmakiya Avatar answered Feb 19 '23 10:02

nmakiya