Repository navigation
Import Prism without creating the global instance - #4168
Open
DmitrySharabin wants to merge 1 commit into
Open
DmitrySharabin wants to merge 1 commit into
DmitrySharabin wants to merge 1 commit into
Conversation
✅ Deploy Preview for dev-prismjs-com ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This was referenced Oct 14, 2026
DmitrySharabin
force-pushed
the
self-registration
branch
4 times, most recently
from
October 14, 2026 12:49
1b6a454 to
28b8550
Compare
DmitrySharabin
force-pushed
the
self-registration
branch
3 times, most recently
from
October 15, 2026 12:41
7177f23 to
989514e
Compare
DmitrySharabin
force-pushed
the
self-registration
branch
from
November 10, 2026 10:28
989514e to
e3b8edc
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Initialization-order bugs can trigger highlighting before DOMContentLoaded and leave components added during cached-plugin replay unregistered with the global instance.
2 open issues
What changed in this PR
Separates the Prism class from singleton initialization, allowing applications to create isolated instances without automatic highlighting. A shared component registry supports the global instance and reuse of the classic-script build.
Changes:
- Exposes dedicated core and global package entries.
- Moves page configuration and automatic highlighting out of the constructor.
- Adds tests for registration order, instance isolation, and mixed classic-script/module usage.
| File | Description |
|---|---|
| tests/fixtures/global-instance/window-config.js | Checks global-variable configuration. |
| tests/fixtures/global-instance/page-config.js | Checks page settings and instance isolation. |
| tests/fixtures/global-instance/no-global.js | Checks modules avoid creating a global variable. |
| tests/fixtures/global-instance/iife.js | Simulates loading the classic-script build. |
| tests/fixtures/global-instance/iife-reused.js | Checks instance reuse and component registration. |
| tests/fixtures/global-instance/iife-hooks.js | Isolates simulated build modules. |
| tests/fixtures/global-instance/iife-highlighted-once.js | Counts automatic highlighting passes. |
| tests/fixtures/global-instance/core-entry.js | Checks core imports avoid singleton creation. |
| tests/fixtures/global-instance/added-before.js | Checks registration before singleton creation. |
| tests/fixtures/global-instance/added-after.js | Checks registration after singleton creation. |
| tests/core/registry.js | Tests unsubscribe and missing-path errors. |
| tests/core/global.js | Adds isolated-process singleton tests. |
| src/types.d.ts | Removes the instance-level manual option. |
| src/registry.js | Introduces the shared component registry. |
| src/plugins/autoloader/autoloader.js | Uses unified instance registration. |
| src/load-languages.js | Uses unified instance registration. |
| src/global.js | Re-exports the non-auto-starting singleton. |
| src/core/tokenize/util.js | Removes singleton fallback from grammar resolution. |
| src/core/tokenize/tokenize.js | Uses the calling instance for tokenization. |
| src/core/tokenize/match.js | Removes singleton fallback from grammar matching. |
| src/core/prism.js | Creates or reuses the singleton and connects its registry. |
| src/core/highlight.js | Uses the calling instance for highlighting. |
| src/core/highlight-element.js | Uses the calling instance for element highlighting. |
| src/core/highlight-all.js | Uses the calling instance for page highlighting. |
| src/core/classes/prism.js | Isolates constructor settings and adds register(). |
| src/core/classes/plugin.js | Routes dependencies through unified registration. |
| src/core/classes/component-registry.js | Adds subscriptions and optional loading paths. |
| src/core.js | Exports the class without importing the singleton. |
| src/config.js | Separates automatic-highlighting settings from instance config. |
| src/auto-start.js | Centralizes automatic highlighting. |
| scripts/build.js | Adds the core build entry. |
| package.json | Exposes core and global package exports. |
Review effort: Balanced
DmitrySharabin
force-pushed
the
self-registration
branch
3 times, most recently
from
November 12, 2026 16:10
7dd8caa to
34f7931
Compare
- `new Prism()` no longer highlights the page, and the `manual` option is gone: call `highlightAll()` yourself Closes #4149 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DmitrySharabin
force-pushed
the
self-registration
branch
from
November 12, 2026 16:25
34f7931 to
5133b65
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Nothing pulls in the global instance on import anymore: the
Prismclass no longer imports it, and languages and plugins add themselves to a registry that imports onlyComponentRegistry(#4156, #4158). Only the IIFE build (prism.js) createsglobalThis.Prism.new Prism()no longer reads the page config or highlights the page, and themanualoption is gone. Code that creates its own instance passes its settings to the constructor and callshighlightAll()itself.Closes Should plugins register themselves, and how do we import the
Prismclass without side effects? #4149Changed lines
src/registry.js(new)src/core/prism.jssrc/auto-start.jssrc/global.jssrc/config.jssrc/core.jssrc/core/classes/prism.jssrc/core/classes/component-registry.jssrc/core/classes/plugin.jssrc/core/highlight-element.jssrc/core/highlight.jssrc/core/highlight-all.jssrc/core/tokenize/match.jssrc/core/tokenize/tokenize.jssrc/core/tokenize/util.jssrc/load-languages.jssrc/plugins/autoloader/autoloader.jssrc/types.d.tspackage.jsonscripts/build.jstests/core/global.js(new)tests/fixtures/global-instance/(new, 11 files)tests/core/registry.js🤖 Generated with Claude Code