arvgta / ajaxify

Ajaxify - An Ajax Plugin
https://4nf.org/
275 stars 124 forks source link

Issue with script execution #228

Closed misog closed 2 years ago

misog commented 2 years ago

Hi, I use emoji JS plugin which is correctly re-initialized by ajaxify but CSS of the plugin was broken. So I went to set up PHP testing site to reproduce the issue but encountered JS issue: Here is code and preview: https://phpsandbox.io/e/x/ymp6u?layout=EditorPreview&defaultPath=%2F&theme=dark&showExplorer=no&openedFiles=

However open directly the URL for JS errors in console: https://ymp6u.ciroue.com/

Uncaught TypeError: this is undefined
    iFn https://4nf.org/ajaxify.js:79
    <anonymous> https://ymp6u.ciroue.com/?reload=1660049574.0162 line 278 > injectedScript:2
    _apptxt https://4nf.org/ajaxify.js:278
    _addtxt https://4nf.org/ajaxify.js:270
    _onetxt https://4nf.org/ajaxify.js:267
    a https://4nf.org/ajaxify.js:253
    a https://4nf.org/ajaxify.js:326
    a https://4nf.org/ajaxify.js:309
    _addScripts https://4nf.org/ajaxify.js:281
    a https://4nf.org/ajaxify.js:256
    _lSel https://4nf.org/ajaxify.js:161

Edit: The problem was solved when I removed addEventListener('DOMContentLoaded', (event) => { and just let the initialization run in <script>. Here is the issue I had: https://github.com/arvgta/ajaxify/issues/229 Edit 2: Regarding this issue, maybe custom script execution handler could be allowed (ex. evalScripts(element)). Or to change script execution to one of the other PJAX projects:

MoOx https://github.com/MoOx/pjax/blob/master/lib/execute-scripts.js https://github.com/MoOx/pjax/blob/master/lib/eval-script.js

PaperStrike https://github.com/PaperStrike/Pjax/blob/main/src/libs/executeScripts/Script.ts https://github.com/PaperStrike/Pjax/blob/main/src/libs/executeScripts/index.ts

Or https://github.com/falsandtru/pjax-api

Or https://stackoverflow.com/questions/1197575/can-scripts-be-inserted-with-innerhtml

arvgta commented 2 years ago

Thanks for opening the two new issues!

Yes, also DOMContentLoaded handling is a pain in the plain vanilla Ajaxify. I think that is what's causing the problem because of this entry in your error log:

Maybe have a look at this currently closed issue ->

(it is closed at the moment but still an issue, I'm afraid)

I will check out the links to PJAX etc. that you have kindly provided...


Had a look especially at this:

Very interesting - especially the synthetic checking for document.write with match(). However, I would not like to overhaul the complete script handling at the moment...

arvgta commented 2 years ago

Hi there,

are you happy with your workaround (replacing the DOMContentLoaded handler) or is there anything else I can do?