-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Defer breaks autoload (when loading page without having resources cached) #2102
Comments
Cannot reproduce. |
Very weird. I now also can't reproduce in a minimal example. Also I am using FireFox 70.0 (64-Bit) |
Well, in any case this is the page: https://dev.aura-dev.team/documentation/test |
Can kinda reproduce. However, could you please describe what breaks? In both FF 70 and Chrome 77, I only see that the PHP code isn't highlighted because |
Can we even fix this? We could use |
This is probably because all the different Prism files have to be loaded in a specific order and the |
|
I didn't know that. That's for pointing that out. I can reproduce the issue you describe now albeit each with a low probability of occurrence. Everything seems to be working fine in Chrome and Edge, so maybe it's a FireFox issue? I'll look more closely at this soon. If you find any hints or patterns, please share. |
I'll be doing some additional testing myself. |
That would be great. Thanks! |
I am seeing this in the console:
What is mermaid and why are you serving Prism from it? |
Ohhhh, I see, the autoloader is using the last script to get the path, and the path is wrong, because |
Couldn't it be fixed by iterating |
I don't think that would work if Prism was bundled together, but what we could do (looking at the code) is query for an element with In the short term, if you put the set of Prism elements last (with the autoloader dead last) instead of mermaid, that should fix it. Alternatively, you could add |
I think I tried that and it didn't quite work. But how about you try these things in order: Search all scripts for:
Use And be sure to properly document that. @RunDevelopment do you want me to open a separate issue for the other race conditions? |
Nah, just leave it here. They are both caused by Also, regarding getting the current script: We have the same issue in Prism Core and every plugin which can be configured using The only reason we don't use We could also just give IE11 the short end of the stick #1578. |
I mean having a util method is a great idea. While I do understand not wanting to use Btw Opera Mini doesn't support it either: https://caniuse.com/#feat=document-currentscript P.S.: Since this whole issue only really appears when using |
Now that I'm back home I noticed that the issues are worse. The difference between work and home is that my home internet is a lot slower. |
So I created a standalone HTML page that displays the bug (not minimal, but I think other scripts help bringing the issues out). It helps if you put the page on a (slow) webserver. As locally I can't seem to reproduce any of the issues except the wrong script tag issue, but online they still all happen. |
Requires: - prism to be loaded last - prism autoload to be the last script Knowledge gained from PrismJS/prism#2102
Alright, I think I know what causes the race condition. Since the (You can verify that this is indeed what's going on by setting a breakpoint in e.g This is a bit of an issue because we'll have to wait for resources that might be loaded. <script defer data-manual src="https://cdn.jsdelivr.net/npm/prismjs@1.17.1/prism.min.js" integrity="sha384-ccmyu9Bl8HZLIVEUqF+ZzcZTBPB8VgMI2lQpOsNDOvro/1SfRnz3qkub0eUxof1s" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/prismjs@1.17.1/plugins/autoloader/prism-autoloader.min.js" integrity="sha384-xF5Qt8AUh+k8ZzozF9d1iDRKeeP1m9PPJKKhy3R/O4+5JccihNLvy1fIuGnkye7+" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/prismjs@1.17.1/plugins/line-numbers/prism-line-numbers.min.js" integrity="sha384-g0u6zLvZF3g2I+/vETu7YYk74PXoDBNGy5qtL04/uW6PJGMDeax43A5hFa55xaAT" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/prismjs@1.17.1/plugins/toolbar/prism-toolbar.min.js" integrity="sha384-Q7kIVs9c3Zyij/OpKzuVFFpRTTXHL3qytFywO0AtJdmisfKKSEsnoc7pHfkxgXZX" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/prismjs@1.17.1/plugins/copy-to-clipboard/prism-copy-to-clipboard.min.js" integrity="sha384-V+ZXzru/5DpvSuLtIS2SctoAyvpigW+zF56aiGLPc+PvQxO3EkpeYDUw6t1Y6d9y" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/prismjs@1.17.1/plugins/show-language/prism-show-language.min.js" integrity="sha384-xnJRKz3VKJloaoR0FNJVmbJ55eTSeuztu0Okhd9vvz2hblDQc0UJWVkj3sIikslo" crossorigin="anonymous"></script>
<script defer>Prism.highlightAll();</script>
<!-- defer won't do anything --> So, instead of using the if (document.readyState !== 'loading' && !script.defer) {
// requestAnimationFrame
} else {
document.addEventListener('DOMContentLoaded', highlightAutomaticallyCallback);
} Have I verified that this fix works? |
Reordering the scripts so that autoload is actually the very last script seems to work too btw. But glad you found the issue. I'd go with this snipped ( Great job for figuring this out. Also document that P.S.: I'm willing to test the fix. The page is not live anyways. |
Browsers are weird |
Ok, I just verified that the fix works. I'll make a PR. |
This fixes a race condition that can occur when deferring Prism components. For more details see #2102.
Do you have an ETA for 1.17.2? |
This is gonna be part of Prism 1.18.0 which will be released soon. Maybe a week or so? |
Ah perfect. I'll just wait for that. |
How's 1.18 coming along? |
Sorry, I've been quite busy and hadn't much time. We're currently wrapping up the last PRs which are going to be included. |
Information:
Description
When the page is loaded without the JS resources being cached and the scripts are marked with
defer
then the syntax highlighting is not applied.Example
Without
defer
(workking): https://jsfiddle.net/f5vj903e/With
defer
(not working): https://jsfiddle.net/f5vj903e/1/The text was updated successfully, but these errors were encountered: