Skip to content

fix(core): dev-mode lingui macro plugin never fires on Windows — admin stuck on loading screen#1941

Open
dchaudhari7177 wants to merge 2 commits into
emdash-cms:mainfrom
dchaudhari7177:fix/windows-dev-lingui
Open

fix(core): dev-mode lingui macro plugin never fires on Windows — admin stuck on loading screen#1941
dchaudhari7177 wants to merge 2 commits into
emdash-cms:mainfrom
dchaudhari7177:fix/windows-dev-lingui

Conversation

@dchaudhari7177

@dchaudhari7177 dchaudhari7177 commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes a Windows-only dev-mode failure where the admin never gets past "Loading EmDash…". Every admin astro-island fails hydration — first Could not resolve "babel-plugin-macros", then ReferenceError: process is not defined — because the Lingui macro transform is being skipped and raw @lingui/*/macro imports reach the browser.

linguiMacroPlugin in packages/core/src/astro/integration/vite-config.ts gates its transform and locale-catalog resolveId on id.startsWith(adminSourcePath). Vite ids use forward slashes on every platform, but path.resolve() returns backslashes on Windows — so the prefix check never matches and the transform silently skips every admin file. Two follow-on Windows landmines sit behind it: await import() of a bare C:\… babel path (Node's ESM loader parses c: as a URL protocol), and the locale redirect returning a bare Windows path that reaches the ESM loader from useLocale.ts.

Three fixes, all no-ops on POSIX:

  1. Compare ids against a forward-slash-normalized adminSourcePath.
  2. import(pathToFileURL(babelCorePath).href).
  3. Return the locale redirect as a file:// URL only on win32 — POSIX returns the identical bare path as before.

Closes #

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (if applicable). Do not include messages.po changes except in translation PRs — a workflow extracts catalogs on merge to main.
  • I have added a changeset (if this PR changes a published package)
  • New features link to an approved Discussion: https://github.com/emdash-cms/emdash/discussions/...

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool:

Screenshots / test output

Verified on Windows 11 (Node 24, pnpm 11): before — admin permanently on the loading screen with the hydration errors above; after — the setup wizard renders and hydrates cleanly (document.querySelectorAll('astro-island[ssr]').length === 0), walkable through the Site and Account steps. tsgo --noEmit and oxlint --type-aware on packages/core both pass; prettier --check is clean. There is no dev-only Vite-plugin test harness in the repo to add a unit test against, so verification is the live Windows repro above.

In dev, linguiMacroPlugin gates its transform and locale redirect on
id.startsWith(adminSourcePath). Vite module ids use forward slashes on
every platform while path.resolve() produces backslashes on Windows, so
the prefix check never matched there: admin source reached the browser
with raw @lingui/*/macro imports, hydration of every admin island failed
(first 'Could not resolve babel-plugin-macros', then 'process is not
defined' from the babel machinery landing in the client bundle), and the
admin sat on 'Loading EmDash...' forever.

Three Windows-specific repairs, all no-ops on POSIX:
- compare ids and adminSourcePath in forward-slash space
- import @babel/core via pathToFileURL (import() of a bare 'C:...' path
  parses 'c:' as a URL protocol)
- return the locale-catalog redirect as a file:// URL on win32 for the
  same reason; POSIX keeps the exact same bare path as before

Verified on Windows 11: the demo admin setup wizard now hydrates
(astro-island count 1, unhydrated 0) where it previously never left the
loading screen.
Copilot AI review requested due to automatic review settings July 11, 2026 07:30
@changeset-bot

changeset-bot Bot commented Jul 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b2249d1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 16 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/do-demo-site Patch
@emdash-cms/do-solo-demo-site Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

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

@github-actions github-actions Bot added review/needs-review No maintainer or bot review yet area/core size/S labels Jul 11, 2026
@github-actions

github-actions Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a Windows-only dev-mode failure where Lingui macros in the admin source weren’t being transformed, causing @lingui/*/macro code to leak into the browser bundle and leaving the admin stuck on “Loading EmDash…”. The change is confined to the Vite integration plugin in packages/core, improving cross-platform path handling without altering POSIX behavior.

Changes:

  • Normalize Windows paths to forward-slash form before startsWith checks so the Lingui macro transform reliably runs on Windows.
  • Convert @babel/core dynamic import to a file:// URL to avoid Windows drive-letter ESM import parsing issues.
  • On Windows only, redirect locale catalog imports to file:// URLs so Node’s ESM loader accepts the resolved paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a focused, well-reasoned fix for a real Windows dev-mode breakage. The diagnosis is correct: Vite module IDs use forward slashes, but path.resolve() returns backslashes on Windows, so the linguiMacroPlugin prefix check silently skipped every admin file. The two follow-on Windows landmines — import() of a bare C:\... babel path and the locale redirect reaching Node's ESM loader — are also real. The change is minimal and leaves POSIX behavior byte-for-byte unchanged, which is the right conservative posture.

I checked the diff, the full vite-config.ts, the admin locale loading code (loadMessages.ts / useLocale.ts), existing changesets, and test coverage. The implementation looks correct, but the PR is missing a changeset for the published emdash package, which AGENTS.md requires for any published-package change. I also noted one cosmetic formatting nit.

Headline: fix is correct; add a changeset before merge.


Findings

  • [needs fixing] packages/core/src/astro/integration/vite-config.ts:1

    This PR changes packages/core, a published package (0.29.0), but there is no .changeset/*.md for it. AGENTS.md requires a changeset for any published-package change. Since this is a user-visible bug fix (dev mode broken on Windows), it should be documented for the next release.

    Please add a changeset such as:

    ---
    "emdash": patch
    ---
    
    Fixes admin dev-mode loading screen on Windows by normalizing path separators and converting Windows absolute paths to `file://` URLs for the Lingui macro plugin.
  • [suggestion] packages/core/src/astro/integration/vite-config.ts:73

    Nit: add a blank line between the toPosixPath helper and the linguiMacroPlugin JSDoc to keep the file consistent with the rest of the codebase.

@github-actions github-actions Bot added review/needs-rereview Author pushed changes since the last review and removed review/needs-review No maintainer or bot review yet labels Jul 11, 2026
@dchaudhari7177

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core cla: signed review/needs-rereview Author pushed changes since the last review size/S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants