Skip to content

Keep the message catalogs out of client files with a lint rule - #891

Merged
richshaw merged 3 commits into
mainfrom
claude/issue-620-client-lint
Nov 13, 2026
Merged

richshaw merged 3 commits into
mainfrom
claude/issue-620-client-lint

Conversation

@richshaw

Copy link
Copy Markdown
Owner

Fixes #620.

Merge after #889. This is the second half of #620: #889 adds the translator and catalogs; this adds the lint rule that keeps them out of client bundles.

The stack

PR 2 of the localization stack (#619). Based on #889 (claude/issue-620-i18n-core); review against that branch.

The problem

src/i18n/translator.ts imports every language's catalog, and so does everything that imports it. If a 'use client' file imported the translator, src/i18n/server.ts or a catalog itself, every language's text would go into that page's JavaScript. server-only can't guard them, because it throws under tsx and vitest, and client files live all over src/, so a path-based rule would miss some.

The fix

  • A local ESLint plugin, opensignup, in eslint.config.mjs, with one rule so far: opensignup/no-catalogs-in-client. It looks only at files whose directive prologue holds 'use client' (the way Next decides), and reports an import of:

    • a catalog in src/messages/ (en.json, and any language added later);
    • a module that loads every catalog: src/i18n/translator.ts, src/i18n/server.ts, and src/i18n/testing/translator.ts, which the issue doesn't name but carries every catalog for the same reason.
  • However it's imported: @/ or relative paths, with or without an extension, side-effect imports, import attributes, export … from and export * from, import(), require(), and an import() whose path is built from a template (import(`@/messages/${locale}.json`)), which the bundler resolves to every file in that folder.

  • Type-only imports pass (import type, import { type X }, export type): they're compiled away and bring nothing into the bundle. I checked that SWC drops import { type X } from '…' entirely, not leaving import '…' behind.

  • The generated declaration (src/messages/en.d.json.ts) is allowed: it imports nothing, so importing it can't pull a catalog in. The rule's .json check is written so @/messages/en.d.json (which resolves to it) isn't mistaken for a catalog.

  • The message says why and what to do instead, for example:

    A 'use client' file can't import '@/i18n/server': it loads every language's message catalog, and all of them would go into the browser's JavaScript. Translate in a server component and pass the text in as props. (A messages provider for client components comes with The public signup page and the sign-up dialog are English-only #629.)

  • Built to take more rules. The plugin is registered in a block of its own for every file, and each rule is turned on in a block for the files it's meant for. Nothing checks the message catalogs, or catches new hard-coded text #623 adds its text-prop rule to opensignup.rules and turns it on per directory. The public signup page and the sign-up dialog are English-only #629 adds its provider rule the same way and updates CLIENT_TEXT_INSTEAD to name ClientMessages. A module that The public signup page and the sign-up dialog are English-only #629 adds to load catalogs on the server (messagesFor) goes into CATALOG_IMPORTERS.

What it doesn't catch

A module without the directive that a client file imports, which itself imports the translator. Lint looks at one file at a time. As the issue says, pnpm budgets is the guard there: a client chunk with every catalog in it goes over the budget.

Where the issue was out of date

Nothing for this half. The issue names the translator, server.ts and catalogs; src/i18n/testing/translator.ts came with #889 and is covered too.

No CHANGELOG entry: nothing anyone sees or sets up changes.

Tests

src/i18n/no-catalogs-in-client.test.ts lints fixtures with ESLint's lintText through the repo's own eslint.config.mjs, not RuleTester. The repo has no pattern for lint tests yet, tsconfig.json has allowJs: false (so a TypeScript test can't import the rule from the .mjs without a declaration file), and running the real config also proves the rule is on for the app's files. It fails if a fixture doesn't parse, so a broken fixture can't pass without being looked at.

  • 16 imports fail in a 'use client' file: each forbidden module, by each kind of import above.
  • The same 16 pass in a server file.
  • 10 imports pass in a 'use client' file: React, next-intl, @/i18n/config, four kinds of type-only import, the generated declaration, a JSON file outside src/messages, and an import() built from a template in a folder without catalogs.
  • The directive is found written with double quotes, after a comment, or after 'use strict'; a 'use server' file passes.
  • The message names the import, the reason and the alternative.

I broke the rule on purpose to check the tests catch it: with the rule off, the 16 client cases fail; with every file treated as a client file, 17 server cases fail; with type-only imports not skipped, the 4 type cases fail; with template paths not followed, the 2 template cases fail; with a plain .json check, the declaration case fails. I also added import { getServerTranslator } from '@/i18n/server' to a real client component (src/components/ui/Popover.tsx) for a moment, and eslint reported it with the message above.

Ran in this session, all passing: pnpm lint, pnpm format:check, pnpm typecheck, pnpm knip, pnpm test (189 files, 2253 tests). No pnpm build: nothing that runs in the app changed.


Generated by Claude Code

Part of #620: the core. next-intl and use-intl 4.14.9, pinned together
(icu-minify too, through an override), with next.config.mjs wrapped in
next-intl's plugin. src/messages/en.json is the English catalog, and
next-intl's AppConfig is typed from it, through the declaration the
plugin writes, so a missing key or a wrong argument fails typecheck.

src/i18n holds the pure locale config (CATALOG_LOCALES, SHIPPED), a
synchronous translator on use-intl/core with English filled in under
any other language, the server wrapper that logs what goes wrong, the
request config the plugin needs, and an English translator for tests
that throws.

The site footer's labels are the first text in the catalog, so the
translator is proven in a server component, on static and dynamic
pages. A new check runs it under the worker's toolchain. No page's
first-load JavaScript changes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
A local ESLint plugin in eslint.config.mjs, with one rule so far:
opensignup/no-catalogs-in-client. In a file that opens with a 'use client'
directive, it reports any import of a catalog in src/messages, or of the
translators that load every catalog (src/i18n/translator.ts, server.ts and
testing/translator.ts), since either would put that text in the browser's
JavaScript. It reads the directive rather than matching paths, follows
@/ and relative paths, re-exports, import(), require() and import paths
built from a template, and lets type-only imports through, since those are
compiled away. The message says why and what to do instead.

The tests lint fixtures through the repo's own config, so they also prove
the rule is on for the app's files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt
@richshaw richshaw added pipeline:tophat pipeline:working A session is working on it right now labels Nov 13, 2026 — with Claude
@richshaw
richshaw requested a balanced review from Copilot November 13, 2026 22:45

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

Copy link
Copy Markdown
Owner Author

Tophat: passed

Ran d5f43d9 locally. Nothing to click here: the PR changes only eslint.config.mjs and adds a test, so this was a developer's-eye check. I wrote throwaway components under src/components/, ran pnpm lint and npx eslint on them, then deleted them (the tree is clean again). No app, browser or database was needed.

Check Result What I saw
'use client' file imports the translator, then a catalog, then @/i18n/server ✅ Each one fails with opensignup/no-catalogs-in-client, at the import path, e.g. 3:37 A 'use client' file can't import '@/i18n/server': it loads every language's message catalog, and all of them would go into the browser's JavaScript. Translate in a server component and pass the text in as props. (A messages provider for client components comes with #629.)
The same three imports in a server component ✅ Passes
A client component using React, useTranslations from next-intl and @/i18n/config ✅ Passes
The same import added to a real client component (src/components/ui/Popover.tsx), then reverted ✅ Reported, same message
Relative paths (../../messages/en.json, ../../i18n/translator, ../../i18n/server.ts, ../../i18n/testing/translator) ✅ All four caught
Odd but valid paths (@/i18n/../messages/en.json, ./../../messages//en.json, @/i18n/translator.ts) ✅ All caught
Re-export from a client file (export { … } from, export * as server from) ✅ Caught in the re-exporting file. A client file importing that file isn't flagged, which is fine because the re-exporter already fails lint.
Re-export through a module without the directive, imported by a client file ➖ not caught As the PR says, lint looks at one file at a time. No real client file does this today (the only real importer, site-footer.tsx, is reached only from server files).
import type, import { type X }, import type en from '…json' ✅ Pass, as they should. A mixed import { type Namespace, getTranslator } is caught.
next/dynamic(() => import('@/i18n/server')), import(`@/messages/${locale}.json`), import(`../../i18n/${name}`), require('@/i18n/translator') ✅ All caught
import en from '@/messages/en' (no extension), '@/messages/en.json?raw' ➖ not caught Doesn't matter: pnpm typecheck fails on both (TS2307 Cannot find module)
import('@/messages/' + locale + '.json') (built with +) ➖ not caught Lint and typecheck both let this through, and since it's a lazy chunk, the first-load budget wouldn't catch it either. It's unlikely in practice, since the template form is caught and is the usual way to write it. Optional: treat a + chain that starts with a string the way the template case is treated.
pnpm lint on the whole repo ✅ Exit 0
pnpm lint time, interleaved with main (3 runs each, another agent's dev server running) ✅ main 12.5 / 11.3 / 11.0 s; this PR 13.5 / 11.3 / 11.9 s, which is within the noise. TIMING=all puts the new rule at 4–6 ms for the whole repo (0.1–0.2%).
pnpm test src/i18n/no-catalogs-in-client.test.ts ✅ 44 passed

In the editor: the error sits on the import path itself, so the squiggle goes under '@/i18n/server'. The message names that import as written, says why it's a problem (every language's text in the browser's JavaScript), and gives the alternative (translate in a server component and pass props, with a pointer to the #629 provider). A contributor can act on it without opening the rule.

No UX change: nothing a person using OpenSignup sees or does is affected.

No screenshots: there's nothing on screen to show. Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt


Generated by Claude Code

@richshaw richshaw left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Review: passed (round 1)

This is the second half of #620: a local ESLint plugin, opensignup, in eslint.config.mjs, with one rule, opensignup/no-catalogs-in-client, that fails a 'use client' file importing a catalog in src/messages/, src/i18n/translator.ts, src/i18n/server.ts or src/i18n/testing/translator.ts. It does it well. The directive is read from the prologue the way Next reads it, stopping at the first statement that isn't a directive. @/ and relative specifiers resolve to absolute paths against the config's own folder, so the rule doesn't depend on the cwd. Static, side-effect, export … from, export *, import(), require() and template-built import() paths are all checked. Type-only imports are skipped, which is safe because tsconfig.json doesn't set verbatimModuleSyntax, so import { type X } is elided whole. The plugin is registered once for every file and each rule is turned on in its own files block, so #623's text-prop rule and #629's provider rule each slot in as one entry in opensignup.rules plus one block. #620's "Done when" item "A client file that imports the translator fails lint" is met, and tested through the real config.

I probed it with 24 fixtures of my own through the repo's config. There were no false positives on typeof import('@/messages/en.json') in a type, @/i18n/config, import() from other folders, or a 'use client' that isn't in the prologue (Next ignores that one too). .ts client files and odd paths (@/i18n/translator.js, ./translator from inside src/i18n/) are caught. The tests prove what they claim: 16 forbidden imports in a client and in a server file, 10 allowed, the directive variants and the message, 44 in all. They run through lintText with the real config at a path under src/components/, so they'd also fail if the rule were switched off or its files glob stopped covering app code, and a fixture that doesn't parse throws instead of passing unseen.

Blocking (0): none.

Optional (3):

  • eslint.config.mjs:90 (check()): import('@/messages/' + locale + '.json') isn't caught (the tophat found it). It matters a little, not much. Webpack makes a context module from a + chain just as it does from a template. Typecheck lets it through (Promise<any>), and since each catalog would be a lazy chunk, the first-load budget wouldn't see it either, so nothing guards it. But the template form is the usual way to write it, and that one is caught, so this isn't worth a round. When the rule is next touched (#623 adds to this plugin), a + chain whose leftmost operand is a string literal could be treated like a template head, with one more FORBIDDEN case.
  • eslint.config.mjs:21 (CATALOG_IMPORTERS): the list fails open. A new module under src/i18n/ that loads catalogs passes until someone adds it here, as the PR body already plans for #629's messagesFor. Denying all of src/i18n/ except an allowlist (config, later the client provider) would fail closed instead. It's a judgement call, noted, not asked for.
  • PR body: it ends with the footer alone. The stack's two attribution lines before it, 🤖 Generated with [Claude Code](https://claude.com/claude-code) and the session link, are missing. That's metadata, not code.

Earlier threads: none. Copilot couldn't review (quota used up), so this went ahead without it.
Checks: CI is green on d5f43d9 (lint-type-test, e2e). Locally I ran pnpm test src/i18n/no-catalogs-in-client.test.ts (44 passed) and the 24-fixture probe above through the real config. The tophat passed on this same SHA, so no runtime code has changed since.

Gate is auto: only eslint.config.mjs and a new test change, with no visible change and nothing high-risk. Per "Merge after #889", it lands after #889.

Session: https://claude.ai/code/session_016YZ9SVnYjqfPQCMgeA7pDt


Generated by Claude Code

Base automatically changed from claude/issue-620-i18n-core to main November 13, 2026 23:05
@richshaw
richshaw merged commit 62c58b3 into main Nov 13, 2026
5 checks passed
@richshaw
richshaw deleted the claude/issue-620-client-lint branch November 13, 2026 23:12
@richshaw richshaw removed pipeline:merge pipeline:working A session is working on it right now labels Nov 13, 2026 — with Claude
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenSignup has no message catalogs or translator, so none of its text can be translated

3 participants