11import Prism from './global' ;
22import autoloader from './plugins/autoloader/prism-autoloader' ;
3+ import { documentReady } from './util/async' ;
34
45Prism . components . add ( autoloader ) ;
56
@@ -22,7 +23,6 @@ export const PrismConfig = {
2223 * ```
2324 *
2425 * @default false
25- * @public
2626 */
2727 manual : false ,
2828} ;
@@ -34,29 +34,11 @@ if (typeof document !== 'undefined' && typeof window !== 'undefined') {
3434 PrismConfig . manual = true ;
3535 }
3636
37- const highlightAutomaticallyCallback = ( ) => {
37+ void documentReady ( ) . then ( ( ) => {
3838 if ( ! PrismConfig . manual ) {
3939 Prism . highlightAll ( ) ;
4040 }
41- } ;
42-
43- // If the document state is "loading", then we'll use DOMContentLoaded.
44- // If the document state is "interactive" and the prism.js script is deferred, then we'll also use the
45- // DOMContentLoaded event because there might be some plugins or languages which have also been deferred and they
46- // might take longer one animation frame to execute which can create a race condition where only some plugins have
47- // been loaded when Prism.highlightAll() is executed, depending on how fast resources are loaded.
48- // See https://github.com/PrismJS/prism/issues/2102
49- // See https://github.com/PrismJS/prism/issues/3535
50- const readyState = document . readyState ;
51- if (
52- readyState === 'loading' ||
53- ( readyState === 'interactive' && script && script . defer && ! script . async )
54- ) {
55- document . addEventListener ( 'DOMContentLoaded' , highlightAutomaticallyCallback ) ;
56- }
57- else {
58- window . requestAnimationFrame ( highlightAutomaticallyCallback ) ;
59- }
41+ } ) ;
6042}
6143else {
6244 PrismConfig . manual = true ;
0 commit comments