Skip to content

fix(script): avoid __name ReferenceError in injected theme script - #391

Closed
CodeLine9 wants to merge 1 commit into
pacocoursey:mainfrom
CodeLine9:clawoss/fix/inline-script-__name-reference-error
Closed

fix(script): avoid __name ReferenceError in injected theme script#391
CodeLine9 wants to merge 1 commit into
pacocoursey:mainfrom
CodeLine9:clawoss/fix/inline-script-__name-reference-error

Conversation

@CodeLine9

Copy link
Copy Markdown

Fixes #370

When using next-themes with Next.js (Turbopack/SWC), the inline theme script throws Uncaught ReferenceError: __name is not defined.

The SWC compiler re-processes inline script content and injects __name() helper calls for function declarations. These helpers are not available at runtime.

Convert the three inner function declarations in script.ts to const arrow functions. SWC does not annotate arrow functions with __name calls, so the injected script remains self-contained.

setColorScheme is moved before updateDOM since const is not hoisted.

…jected script

Next.js SWC/Turbopack re-processes inline script content and injects
__name() helper calls for named function declarations. These helpers are
undefined at runtime, causing "Uncaught ReferenceError: __name is not
defined".

Convert inner function declarations to const arrow functions, which SWC
does not decorate with __name calls.

Fixes pacocoursey#370
@CodeLine9

Copy link
Copy Markdown
Author

Closing — no longer pursuing contributions here.

@CodeLine9 CodeLine9 closed this Apr 19, 2026
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.

[Bug]: Uncaught ReferenceError: __name is not defined in Injected Theme Script

1 participant