Repository navigation
perf(core): keep admin-only code off a site's first request - #4596
Draft
eisenbruch wants to merge 1 commit into
Draft
eisenbruch wants to merge 1 commit into
eisenbruch wants to merge 1 commit into
Conversation
emdash-runtime imported its handlers through the package's main barrel, and the package declared no sideEffects, so any site importing from "emdash" evaluated the API schemas, the WordPress importer, the seed applier and more before rendering a page. Import the handlers from their modules and declare sideEffects, listing src/import/index.ts, which registers the built-in import sources when it loads. A test fails if a module doing work at import time is left off the list, or if the runtime goes back to the barrel. Refs emdash-cms#3313 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RktNvhjty22ohh1GSHXGMq
🦋 Changeset detectedLatest commit: 15dee04 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-test
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-loader
@emdash-cms/registry-moderation
@emdash-cms/registry-verification
upgrade-emdash
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-ai-search
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
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.
What does this PR do?
Refs #3313 (our issue). Two small changes that shrink what a site evaluates when its middleware first loads:
emdash-runtime.tsimported its content, media and revision handlers and the schema registry through./index.js, the package's main barrel. Those names now come from their own modules.packages/core/package.jsondeclaressideEffects. Without it a bundler must keep every module the barrel reaches, so a site that importsgetEmDashCollectionfromemdash(every site) evaluated the API schemas, the WordPress importer, the seed applier and similar code before its first page. The list is**/*.astroand**/*.css(component styles) plus./src/import/index.ts, the one source module that does work at import time: it registers the built-in import sources. Without that entry the registrations vanish from the build silently. I hit this while testing.A new test,
tests/unit/package-side-effects.test.ts, fails if a source module with a top-level call is missing from the list (I checked that it fails without the importer entry), or if the runtime imports the barrel again.Nothing is removed from the bundle; the code moves to chunks loaded by the admin, API and import routes that use it.
Draft because the real-Workers gain is unproven. Measured on our site (EmDash 1.4.0 with this change applied, Astro 7, Cloudflare):
dist/astro/middleware.mjs(onmain)wrangler check startup, same forced build, median of 5 (laptop)So the startup measures #3313 used move clearly, but with the middleware loaded lazily as Astro does by default, I could not see a change in billed first-request CPU or wall time. My guess is that Cloudflare caches compiled code across isolates, so evaluation is cheaper in production than a startup measurement suggests, but I have not confirmed that. My issue said this cost lands on most requests; this data does not support that, and I will correct it on the issue. The change still lowers what counts against the startup limit for any setup that evaluates the middleware at startup.
Rendered output was identical: 26 pages on our dev site (home, lists, articles, events, listings, topics, search, sitemaps) compared across the A/B/A after removing per-request ids. The admin login page, MCP reads and a cron run worked on the changed build.
Type of change
Your connection to this change
Checklist
pnpm typecheckpasses (core)pnpm lintpasses (oxlint --type-aware --deny-warnings, repo-wide)pnpm testpasses (or targeted tests for my change): core unit tests, 494 files, 6,384 testspnpm formathas been run (oxfmt --checkclean repo-wide)AI assistance disclosure
Screenshots / test output
Not applicable.
🤖 Generated with Claude Code
https://claude.ai/code/session_01RktNvhjty22ohh1GSHXGMq