Skip to content

fix: add gt-react rsc missing stubs#1833

Open
ErnestM1234 wants to merge 1 commit into
mainfrom
e/odysseus/react-rsc-missing-stubs
Open

fix: add gt-react rsc missing stubs#1833
ErnestM1234 wants to merge 1 commit into
mainfrom
e/odysseus/react-rsc-missing-stubs

Conversation

@ErnestM1234

@ErnestM1234 ErnestM1234 commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add explicit throwing stubs in gt-react's RSC entry point for default type-surface APIs missing at runtime
  • cover the RSC surface with export and throwing behavior tests
  • add a patch changeset for gt-react

Verification

  • pnpm install
  • pnpm --filter gt-react... build
  • pnpm --dir packages/react exec vitest run src/tests/context-rsc.test.ts
  • pnpm exec oxfmt --check packages/react/src/index.rsc.ts packages/react/src/tests/context-rsc.test.ts .changeset/react-rsc-missing-stubs.md
  • node --conditions=react-server export check for the eight added names

Caveat

  • pnpm --filter gt-react typecheck currently fails on existing src/index.types.ts export of initializeGT from @generaltranslation/react-core/pure, which does not export that member.

Greptile Summary

This PR adds eight explicit throwing stubs to gt-react's RSC entry point (index.rsc.ts) for client-only APIs that were previously absent from the react-server export surface, along with a matching patch changeset and test coverage.

  • New stubs: initializeGTSPA, useLocaleSelector, useRegionSelector, useSetLocale, useSetRegion, useSetEnableI18n, useEnableI18n, and useFormatLocales are now exported from index.rsc.ts and throw a descriptive diagnostic error when called in an RSC context.
  • Tests: The RSC surface test is extended with an export-presence check for all eight stubs and a throwing-behavior test; initializeGTSPA is correctly exercised with rejects.toThrow since its stub is async.
  • Rename: The internal helper failClientComponent is renamed to failClientExport to better reflect its broader usage across hooks and functions, not just components.

Confidence Score: 4/5

Safe to merge; the change is additive and all stubs correctly throw at runtime.

The stubs for useEnableI18n and useFormatLocales carry manually written signatures rather than the type-alias pattern used for all other stubs in this PR, so a future change to those hook signatures in react-core would go undetected by TypeScript. Everything else — the async stub for initializeGTSPA, the rename of failClientComponent to failClientExport, and the new tests — looks correct.

packages/react/src/index.rsc.ts — the useEnableI18n and useFormatLocales stubs lack type alias anchoring.

Important Files Changed

Filename Overview
packages/react/src/index.rsc.ts Adds eight explicit throwing stubs for client-only APIs on the RSC entry point; six stubs are anchored to typed aliases for signature safety, but useEnableI18n and useFormatLocales are typed manually without alias anchoring.
packages/react/src/tests/context-rsc.test.ts Extends the RSC surface test to verify exports and throwing behavior for all eight new stubs; initializeGTSPA is correctly tested via rejects.toThrow for its async path.
.changeset/react-rsc-missing-stubs.md Patch changeset for gt-react describing the RSC stub additions; content is accurate.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Consumer imports from gt-react RSC entry\nindex.rsc.ts] --> B{Is the API\nRSC-compatible?}
    B -- Yes --> C[Real implementation returned\ne.g. useLocale, useGT, T, Branch ...]
    B -- No --> D[failClientExport throws\ndiagnostic error]

    subgraph "New throwing stubs (this PR)"
        D --> E[initializeGTSPA]
        D --> F[useLocaleSelector]
        D --> G[useRegionSelector]
        D --> H[useSetLocale]
        D --> I[useSetRegion]
        D --> J[useSetEnableI18n]
        D --> K[useEnableI18n]
        D --> L[useFormatLocales]
    end

    subgraph "Pre-existing throwing stubs"
        D --> M[GTProvider]
        D --> N[LocaleSelector]
        D --> O[RegionSelector]
    end
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[Consumer imports from gt-react RSC entry\nindex.rsc.ts] --> B{Is the API\nRSC-compatible?}
    B -- Yes --> C[Real implementation returned\ne.g. useLocale, useGT, T, Branch ...]
    B -- No --> D[failClientExport throws\ndiagnostic error]

    subgraph "New throwing stubs (this PR)"
        D --> E[initializeGTSPA]
        D --> F[useLocaleSelector]
        D --> G[useRegionSelector]
        D --> H[useSetLocale]
        D --> I[useSetRegion]
        D --> J[useSetEnableI18n]
        D --> K[useEnableI18n]
        D --> L[useFormatLocales]
    end

    subgraph "Pre-existing throwing stubs"
        D --> M[GTProvider]
        D --> N[LocaleSelector]
        D --> O[RegionSelector]
    end
Loading

Fix All in Claude Code Fix All in Codex

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
packages/react/src/index.rsc.ts:95-103
**Missing type aliases for `useEnableI18n` and `useFormatLocales` stubs**

The six other stubs added in this PR all use `typeof import(...)` type aliases (e.g., `UseSetLocale`, `UseLocaleSelector`) so that TypeScript will catch a signature change in the source hook. `useEnableI18n` and `useFormatLocales` are typed manually instead, so a signature change in `@generaltranslation/react-core/hooks` would silently leave the stubs mismatched. Consider adding:

```ts
type UseEnableI18n = typeof import('@generaltranslation/react-core/hooks').useEnableI18n;
type UseFormatLocales = typeof import('@generaltranslation/react-core/hooks').useFormatLocales;
```

and annotating the stubs accordingly.

Reviews (1): Last reviewed commit: "fix: add gt-react rsc missing stubs" | Re-trigger Greptile

Greptile also left 1 inline comment on this PR.

@ErnestM1234 ErnestM1234 requested a review from a team as a code owner July 4, 2026 02:03
Comment on lines +95 to +103
export function useEnableI18n(): boolean {
return failClientExport('useEnableI18n');
}
export function useLocales() {
return getI18nConfig().getLocales();
}
export function useFormatLocales(_localesProp?: string[]): string[] {
return failClientExport('useFormatLocales');
}

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.

P2 Missing type aliases for useEnableI18n and useFormatLocales stubs

The six other stubs added in this PR all use typeof import(...) type aliases (e.g., UseSetLocale, UseLocaleSelector) so that TypeScript will catch a signature change in the source hook. useEnableI18n and useFormatLocales are typed manually instead, so a signature change in @generaltranslation/react-core/hooks would silently leave the stubs mismatched. Consider adding:

type UseEnableI18n = typeof import('@generaltranslation/react-core/hooks').useEnableI18n;
type UseFormatLocales = typeof import('@generaltranslation/react-core/hooks').useFormatLocales;

and annotating the stubs accordingly.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/react/src/index.rsc.ts
Line: 95-103

Comment:
**Missing type aliases for `useEnableI18n` and `useFormatLocales` stubs**

The six other stubs added in this PR all use `typeof import(...)` type aliases (e.g., `UseSetLocale`, `UseLocaleSelector`) so that TypeScript will catch a signature change in the source hook. `useEnableI18n` and `useFormatLocales` are typed manually instead, so a signature change in `@generaltranslation/react-core/hooks` would silently leave the stubs mismatched. Consider adding:

```ts
type UseEnableI18n = typeof import('@generaltranslation/react-core/hooks').useEnableI18n;
type UseFormatLocales = typeof import('@generaltranslation/react-core/hooks').useFormatLocales;
```

and annotating the stubs accordingly.

How can I resolve this? If you propose a fix, please make it concise.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Fix in Claude Code Fix in Codex

Base automatically changed from odysseus to main July 4, 2026 02:25
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.

1 participant