#3587·emdash

astro dev: native plugin admin components get separate @lingui/react and @tanstack/react-query instances, so the documented useLingui() example crashes

Author: tdhftwCreated Sep 28, 2026Updated Sep 28, 2026
Labelsarea/adminarea/corearea/pluginsbot:workingbot:bug

Description

Under astro dev, a native plugin's React admin components can't reach the admin's Lingui or React Query providers. The documented examples in "React Admin Pages & Widgets" (useLingui() in a page, useQuery() in a widget) crash with:

Error: useLingui hook was used without I18nProvider.
    at useLingui (http://localhost:4399/node_modules/@lingui/react/dist/index.mjs?v=790b4467:16:9)
    at AnalyticsPage (http://localhost:4399/node_modules/<plugin>/src/admin/AnalyticsPage.tsx:15:19)

Expected: plugin components get the same @lingui/react and @tanstack/react-query instances as the admin, so the admin's I18nProvider and QueryClientProvider apply, as the docs describe.

Likely cause. The integration adds @emdash-cms/admin to the client optimizeDeps.include, and Vite's pre-bundle of the admin inlines its own copies of @lingui/react and @tanstack/react-query (in the site's node_modules/.vite/deps, the "useLingui hook was used without I18nProvider" string lives in a chunk of the admin pre-bundle). The plugin's admin entry ships as source and is not pre-bundled, so its imports resolve to the raw packages (/node_modules/@lingui/react/dist/index.mjs?v=…), which are separate module instances with separate React contexts. React itself is fine, since it is pre-bundled separately and shared.

This looks like a sibling of #2873, which covers the same mechanism for emdash/plugin-utils.

Workaround in the plugin. Don't use host-context hooks. Wrap exported pages and widgets in the plugin's own QueryClientProvider, and don't use useLingui().

Possible fix. Pre-bundle the shared admin peers separately, so the admin pre-bundle and plugin sources import the same optimized modules, e.g. optimizeDeps.include: ["@lingui/core", "@lingui/react", "@tanstack/react-query", "@cloudflare/kumo", "emdash/plugin-utils", ...], or dedupe them explicitly.

Steps to reproduce

  1. Create a native plugin with adminEntry / admin.entry and an admin.pages entry. Its component calls useLingui() from @lingui/react, exactly like the docs' ActivityPage example.
  2. Register it in plugins: [] and run astro dev.
  3. Open /_emdash/admin/plugins/<id>/. The page crashes with the error above.

The React Query side is inferred from the same pre-bundle layout. I only reproduced the Lingui crash.

Environment

  • emdash version: 1.0.1 (@emdash-cms/admin 1.0.1, @cloudflare/kumo 2.6.0, @lingui/react 5.9.5, @tanstack/react-query 5.90.21)
  • Astro 7.3.5, @astrojs/cloudflare 14, Vite dev server in workerd
  • Node.js version: 26.7.0
  • Runtime: Cloudflare Workers (astro dev)
  • OS: Linux

Production: astro build produces a single copy of each package in the client output. I have not tested the page at runtime in production.

Screenshots

Not applicable. The plugin page is replaced by the admin's error boundary. The full error is in the logs below.

Logs / error output

bash
[console.error] Error: useLingui hook was used without I18nProvider.
    at useLinguiInternal (http://localhost:4399/node_modules/@lingui/react/dist/index.mjs?v=790b4467:10:10)
    at useLingui (http://localhost:4399/node_modules/@lingui/react/dist/index.mjs?v=790b4467:16:9)
    at AnalyticsPage (http://localhost:4399/node_modules/<plugin>/src/admin/AnalyticsPage.tsx:15:19)
The above error occurred in the <AnalyticsPage> component.
React will try to recreate this component tree from scratch using the error boundary you provided, CatchBoundaryImpl.