Confirmed Overlays sometimes don't run all of their inline scripts (XF 2.3.13)

Kevin

Well-known member
Licensed customer
Affected version
2.3.13
This is being submitted in follow-up to this earlier thread....

When a page is loaded into an overlay, XenForo finds the inline 'script' blocks in that page and runs them. If the page has more than one script, some of the later ones can be skipped. They're never run and stay in the page doing nothing with no error triggered (that I can find).

The problem depends on how long the scripts before it are so the same template can work in one instance and not work in another so it looks random.

What is Happening: The code that collects the scripts (setupHtmlInsert() in js/xf/core.js) works through the page from start to finish and keeps track of how far along in the page text it is. Each time it finds a script it cuts that script out of the page text but it doesn't move the tracker backward for the length that was removed from the page text. So the next search starts ahead of where it actually left off in the page text and it ends up skipping over a section of the page text that is length of the script that was just cut. Any scripts that are in the page text that was jump-forwarded over is missed.

TL/DR: one long script followed closely by a short one means the short one never runs.

How To Reproduce:
  • Make a page that has a long inline script, then a bit of normal HTML, then a second, short script, for example one that writes "second script ran" to the console.
  • Open that page in an overlay.
  • The second script never runs, and its script tag is still sitting inside the overlay.
A real example is {{ dump() }} in a template that's opened as an overlay like I was using in my earlier thread. The dump outputs one large script, plus a short script for each dump that adds the expand/collapse arrows. Those short scripts get skipped, so the dump shows folded arrays like array:10 [] that can't be opened because the arrows to expand the array don't show up. The same template opened as a page instead of an overlay seems to work fine. The missing 'expand' arrows are due to the second small script not being fired because that part of the page text got skipped when the bigger script before it was removed from the page text.

Possible Fixes: Don't cut scripts out of the page text while still searching through it. XenForo could find all the scripts first and remove them afterwards, or do the finding and removing in a single replace() pass. Resetting the bookmark after each cut (XF.scriptMatchRegex.lastIndex = 0) may also work.
 
Back
Top Bottom