Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with script execution #228

Closed
misog opened this issue Aug 9, 2022 · 2 comments
Closed

Issue with script execution #228

misog opened this issue Aug 9, 2022 · 2 comments

Comments

@misog
Copy link

misog commented Aug 9, 2022

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: #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
Copy link
Owner

arvgta commented Aug 9, 2022

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:

  • iFn https://4nf.org/ajaxify.js:79

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
Copy link
Owner

arvgta commented Aug 10, 2022

Hi there,

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

@arvgta arvgta closed this as completed Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants