Repository navigation
fix: stop the theme script failing on every page in production - #9
Merged
Merged
Conversation
Wrangler bundles the Worker with esbuild's keep-names option, which wraps functions in a `__name` helper. next-themes serialises its theme function into an inline script, so that helper call reached the browser and threw "__name is not defined" on every page load. The theme was then applied only after hydration, so dark-mode users saw a flash. Disables keep_names. Nothing in the Worker reads function names at run time, and the app's error classes set their names explicitly.
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.
Problem
Every page on production logs
ReferenceError: __name is not definedfrom an inline script. It predates the recent feature work.Cause
Wrangler bundles the Worker with esbuild's keep-names option on by default, which wraps functions in a
__name(...)helper.next-themescopies its theme function's source into an inline<script>so the theme is set before first paint. The helper call is copied with it, and the helper does not exist in the browser. The script throws, and the theme is applied only after hydration, which dark-mode users see as a flash.Fix
"keep_names": falseinwrangler.jsonc. Nothing in the Worker reads function or class names at run time, and the app's error classes setnameexplicitly.Risk and rollback
This changes how the Worker is bundled, which CI does not exercise (CI builds with
next build, not the Worker bundle). After deploy I will check the page error is gone and that sign-in start, the API and photo search still respond. Rollback iswrangler rollbackto the previous version.Test plan
/app;/api/auth/me, sign-in start,/api/workspaces(401) and/api/unsplash/searchrespond as before