-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Remove document.write for script path and allow external config #120
Conversation
1. Use document.getElementsByTag name to find the script's path. When used async, this fails by providing the wrong path instead of failing catastrophically. 2. Detect if the script was loaded asynchronously by attaching a load event to the body and seeing if it fires. 3. Evaluate the correct script path when it is requested. This gives the user time to manually configuring it using the Papa.SCRIPT_PATH global. If this isn't done and the script was loaded async, throw a helpful error explaining how to fix.
This should remove the need to modify the library. It uses the automatically detected script path if the script was loaded synchronously, otherwise it checks for a global Papa.SCRIPT_PATH, which can be set any time before parse. If it isn't set an exception is thrown. |
Thanks, I'll be taking a look at this shortly. |
This doesn't jive too well when Papa Parse is loaded in the For clarity, what do you think about renaming IS_SYNC to LOADED_SYNC? |
8fd308f
to
8d33f90
Compare
Added a check for document.body (if it's doesn't exist yet it must be synchronous loading) and renamed flag as suggested. |
Getting there; this is a tricky one. There's another subtle bug. If these conditions are satisfied:
then the parse will succeed, but without using a worker. This is unexpected (granted, it is a programmer error, but there is no way to know there is an error until too late). In this case, I think an error/exception should be thrown, like on line 1379. |
…rown DOMContentLoaded event fires sooner fixing the body-async case. If the user reqeusts a worker, try to use one even if no path is set so that a helpful error is shown.
Hey, I can't break this one. Nice work, @edg2s! And thank you. |
Remove document.write for script path and allow external config
Great, you're welcome. We can now use this lib in Wikipedia's VisualEditor. |
That's great news. The new Papa Parse website (which I'm still building) will have a "Powered by Papa" section. Would it be alright if I include VisualEditor? The spot can be a link, too, so if there's a particular page you want it to link to, just let me know. |
Of course, I think https://www.mediawiki.org/wiki/VisualEditor is our "homepage" at the moment. |
When used async, this fails by providing the wrong path instead
of failing catastrophically.
event to the body and seeing if it fires.
the user time to manually configuring it using the Papa.SCRIPT_PATH
global. If this isn't done and the script was loaded async, throw
a helpful error explaining how to fix.
Fixes #119