Repository navigation
fix(core): keep plugin cron alive in astro dev under Cloudflare adapter - #1636
Conversation
The scheduler virtual module decided whether to inject a NodeCronScheduler from Vite's config.command, which the Cloudflare adapter reports as "build" even during `astro dev` (it bundles the worker via a nested Vite build pass). That suppressed the in-process timer, leaving ctx.cron undefined so plugins could not schedule cron tasks and the cron hook never fired. Base the decision on Astro's authoritative command instead, so local dev keeps the in-process timer for plugin cron, scheduled publishing, and cleanup. Closes emdash-cms#1635 Co-Authored-By: Claude Opus 4.8 <[email protected]>
🦋 Changeset detectedLatest commit: 23f440f The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 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-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@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: |
There was a problem hiding this comment.
This is the right fix for the reported bug: the Cloudflare adapter runs a nested Vite build pass during astro dev, so config.command is "build" even though the user is in dev. Threading Astro’s authoritative command into the virtual-modules plugin and mapping only "dev" → "serve" keeps the local Node timer alive for cron, scheduled publishing, and cleanup in that scenario without changing behavior for production Cloudflare builds or non-Cloudflare adapters.
I checked:
- The scheduler generation logic and how
createScheduleris consumed byemdash-runtime.tsto setcronReschedule. - The integration wiring in
packages/core/src/astro/integration/index.ts;commandfromastro:config:setupis captured and passed throughcreateViteConfig. - All call sites of
createVirtualModulesPluginin the repo (only the one internal call plus the new unit tests). - The new test reproduces the exact failure mode (Vite
configResolvedreports"build"while Astro command is"dev") and asserts the scheduler is non-null.
The change is focused, the existing generateSchedulerModule contract is preserved, test coverage is appropriate, and the changeset is present and well-written. I found no issues.
|
Thanks! |
What does this PR do?
Fixes plugin cron being silently inert during
astro devunder the@astrojs/cloudflareadapter.The scheduler virtual module (
virtual:emdash/scheduler) decides whether to inject aNodeCronSchedulerbased on a command. It was reading Vite'sconfig.command, which the Cloudflare adapter reports as"build"even duringastro dev— the adapter produces the worker bundle via a nested Vite build pass. As a resultgenerateSchedulerModulereturnedcreateScheduler = null, the middleware skippedsetContextFactory({ cronReschedule }), andctx.cronwas leftundefined. Plugins could not callctx.cron.schedule(...),_emdash_cron_tasksstayed empty, and the plugincronhook never fired.The fix threads Astro's authoritative
commandinto the virtual-modules plugin and bases the scheduler decision on it (dev→ in-process timer, everything else → null under Cloudflare).astro devnow keeps theNodeCronSchedulerregardless of how the Cloudflare adapter pre-bundles the worker, so plugin cron, scheduled publishing, and cleanup run again in local dev.Closes #1635
Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runAI-generated code disclosure
Screenshots / test output
Added
createVirtualModulesPlugin scheduler wiringtests reproducing the bug (Cloudflare adapter + Astro commanddevwhile Vite reportsbuild). Written test-first: the reproducing test failed (scheduler resolved tonull) before the fix, passes after.🤖 Generated with Claude Code