Skip to content

🐛 TinaCMS admin - Load the extra Prism grammars without require so the admin starts again - #2807

Merged
bradystroud merged 1 commit into
mainfrom
bs/fix-tina-admin-prism-require
Nov 12, 2026
Merged

bradystroud merged 1 commit into
mainfrom
bs/fix-tina-admin-prism-require

Conversation

@bradystroud

Copy link
Copy Markdown
Member

Description

✏️ Since #2781, the Tina admin does not start. It shows "Failed loading TinaCMS assets" for every rule, and the browser console shows:

Error: Dynamic require of "prismjs/components/prism-csharp" is not supported
Failed to load assets

Cause: lib/prism-grammars.ts loads four Prism grammars with require(). The typography components import that file, and the admin bundle contains them through the box and email embeds. The admin is a browser ES module bundle, so require() throws there. The public pages are not affected, because Next.js supports require.

Fix:

  • The grammars load as static imports on the prismjs core instance. The module then copies csharp, bash, powershell and http to the Prism instance of prism-react-renderer, with the same aliases as before (cs, dotnet, sh, shell).
  • PrismJS.manual = true, so the prismjs core does not highlight the code blocks that React renders.
  • A simpler form does not work: if an ES module sets the global Prism and the grammars load after it, the bundler runs the grammar code first, and the admin stops with Prism is not defined. The comment in the file says this.

Tests

  • Production admin in headless Chromium: Dynamic require of "prismjs/components/prism-csharp" is not supported, and the asset error banner.
  • Local admin build (tinacms build --local) with the first fix form: Prism is not defined.
  • Local admin build with this fix: the admin loads. The only console errors are the TinaCloud 401 responses of a test with no login.
  • __tests__/lib/prismGrammars.test.ts: 5 of 5 pass, one new test for PrismJS.manual. The tests check that the grammars still give several token types, so code blocks keep their colors.
  • pnpm lint and pnpm test pass.

Not tested: the editor with a TinaCloud login, and a full site build.

Screenshot (optional)

✏️ Not applicable.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UTtNDpWnuaUUQ2winSSgMb

…e admin starts again

Since #2781, the Tina admin stops at load with "Dynamic require of
"prismjs/components/prism-csharp" is not supported", and it then shows
"Failed loading TinaCMS assets". The admin is a browser ES module bundle,
and lib/prism-grammars.ts used require calls.

- The grammars load as static imports on the prismjs core instance, and the
  module copies them to the Prism instance of prism-react-renderer.
- A form that sets the global Prism from an ES module does not work: the
  bundler runs the grammar code first, and the admin stops with "Prism is not
  defined" (tested).
- PrismJS.manual is true, so the prismjs core does not highlight the code
  blocks that React renders.

Tested: production admin and a local admin build in headless Chromium. Before,
the asset error. After, the admin loads. The grammar tests pass (one new test).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UTtNDpWnuaUUQ2winSSgMb

@joshbermanssw joshbermanssw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bradystroud
bradystroud merged commit e669798 into main Nov 12, 2026
1 check passed
@bradystroud
bradystroud deleted the bs/fix-tina-admin-prism-require branch November 12, 2026 23:23
Comment thread lib/prism-grammars.ts Resolved
@bradystroud

Copy link
Copy Markdown
Member Author

🎬 Explainer video for this pull request (about 40 seconds, no sound): the problem, the change, and how it helps.

🤖 Generated with Claude Code

pr-2807.mp4

bradystroud added a commit that referenced this pull request Nov 13, 2026
…na admin (#2808)

A require call in code that the Tina admin bundles stops the admin in the
browser (#2807). The CI admin build passes with such a call, and Jest runs
CommonJS, so only a person who opens /admin finds it.

- style/noCommonJs is an error for the application code.
- The rule is off for the root config files (*.js) and scripts/, which are
  CommonJS Node scripts.
- lib/appInsights.server.ts keeps its two require calls, with a biome-ignore
  comment that gives the reason.


Claude-Session: https://claude.ai/code/session_01UTtNDpWnuaUUQ2winSSgMb

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

This branch was previously deployed

1 inactive deployment
staging — 9bcd05fc Deployed Nov 12, 2026 by bradystroud via Delete PR Slot #199
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

Successfully merging this pull request may close these issues.

3 participants