fix: add gt-react rsc missing stubs#1833
Open
ErnestM1234 wants to merge 1 commit into
Open
Conversation
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'); | ||
| } |
Contributor
There was a problem hiding this 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:
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!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Verification
Caveat
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 thereact-serverexport surface, along with a matching patch changeset and test coverage.initializeGTSPA,useLocaleSelector,useRegionSelector,useSetLocale,useSetRegion,useSetEnableI18n,useEnableI18n, anduseFormatLocalesare now exported fromindex.rsc.tsand throw a descriptive diagnostic error when called in an RSC context.initializeGTSPAis correctly exercised withrejects.toThrowsince its stub is async.failClientComponentis renamed tofailClientExportto 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
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%%{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] endPrompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix: add gt-react rsc missing stubs" | Re-trigger Greptile