Skip to content

Conversation

@transphorm
Copy link
Member

@transphorm transphorm commented Jul 30, 2025

Summary

  • add a lazyScreen helper component to wrap dynamic imports in <Suspense>
  • use lazyScreen instead of React.lazy across navigation modules

Testing

  • yarn lint
  • yarn build
  • yarn workspace @selfxyz/contracts build (fails: Invalid account for hardhat)
  • yarn types
  • yarn workspace @selfxyz/common test
  • yarn workspace @selfxyz/circuits test (fails: Unsupported signature algorithm)
  • yarn workspace @selfxyz/mobile-app test
  • yarn workspace @selfxyz/mobile-app web (no "Objects are not valid as a React child" error)

https://chatgpt.com/codex/tasks/task_b_688a6860bf88832da3f866cdd8ed7854

Summary by CodeRabbit

  • New Features

    • Improved screen loading experience by introducing a custom lazy loading utility for all navigation screens.
  • Refactor

    • Updated all navigation modules to use the new lazy loading utility for screen components, replacing the previous approach.
    • Removed suspense fallback UI from the main navigation component for streamlined rendering.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 30, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

A new utility function, lazyScreen, was introduced to standardize lazy loading of React components in navigation modules. All usages of React's built-in lazy function for screen components in navigation files were replaced with lazyScreen, ensuring consistent lazy loading behavior across the app. Additionally, the use of React's Suspense component was removed from the main navigation wrapper. No changes were made to navigation options or screen configurations.

Changes

Cohort / File(s) Change Summary
Introduce lazyScreen utility
app/src/navigation/lazyScreen.tsx
Added lazyScreen function to wrap React.lazy with Suspense and fallback, enabling type-safe, consistent lazy loading for screens.
Aesop navigation: Use lazyScreen
app/src/navigation/aesop.ts
Replaced React's lazy with lazyScreen for PassportOnboardingScreen import.
Dev navigation: Use lazyScreen
app/src/navigation/dev.ts
Replaced all React lazy imports with lazyScreen and adjusted formatting for lazy-loaded screens.
Passport navigation: Use lazyScreen
app/src/navigation/passport.ts
Replaced all React lazy imports with lazyScreen for all screen components.
Prove navigation: Use lazyScreen
app/src/navigation/prove.ts
Replaced all React lazy imports with lazyScreen for all screen components.
Recovery navigation: Use lazyScreen
app/src/navigation/recovery.ts
Replaced all React lazy imports with lazyScreen for all screen components.
Settings navigation: Use lazyScreen
app/src/navigation/settings.ts
Replaced all React lazy imports with lazyScreen for all screen components.
Navigation root: Remove Suspense wrapper
app/src/navigation/index.tsx
Removed React Suspense wrapper and fallback UI from the main navigation component; simplified component tree by rendering Navigation directly.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

Lazy screens now load with flair,
Wrapped in Suspense, handled with care.
From settings to passport, the pattern is clean,
A single utility behind each scene.
Suspense steps back, the flow feels light—
Navigation’s future is looking bright!
🚀✨


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7b876b9 and d467e4d.

📒 Files selected for processing (1)
  • app/src/navigation/index.tsx (2 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/implement-lazyscreen-and-update-navigation-files

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@transphorm transphorm changed the title Use lazyScreen helper for screens Fix web app screen loading Jul 30, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
app/src/navigation/prove.ts (1)

7-19: Preserve prop generics as in previous comment
All of these lazyScreen() usages will benefit once the helper exposes the generic type parameter.

🧹 Nitpick comments (4)
app/src/navigation/lazyScreen.tsx (1)

6-15: Consider preserving the wrapped component’s identity and allowing a custom fallback

LazyScreenWrapper loses the original component’s displayName and is recreated for every invocation of lazyScreen, making stack traces less helpful. A tiny tweak gives you better DX at zero runtime cost and lets callers override the fallback when needed.

 export function lazyScreen<T extends object>(
   importer: () => Promise<{ default: React.ComponentType<T> }>,
-): React.ComponentType<T> {
+  fallback: React.ReactNode = <View />,
+): React.ComponentType<T> {
   const LazyComp = React.lazy(importer) as unknown as React.ComponentType<T>;
-  const LazyScreenWrapper = (props: T) => (
-    <Suspense fallback={<View />}>
+  const LazyScreenWrapper: React.FC<T> = (props) => (
+    <Suspense fallback={fallback}>
       <LazyComp {...(props as T)} />
     </Suspense>
   );
+  LazyScreenWrapper.displayName =
+    `Lazy(${LazyComp.displayName ?? LazyComp.name ?? 'Screen'})`;
   return LazyScreenWrapper as React.ComponentType<T>;
 }

Benefits: clearer error traces, optional spinners/place-holders per screen, and no change to the call-sites if you rely on the default.

app/src/navigation/recovery.ts (1)

5-24: Heavy repetition – extract a tiny factory to keep this list tidy

Eight near-identical lazyScreen(() => import(...)) declarations inflate the file. A one-liner helper keeps intent obvious and reduces churn when you add or rename screens.

const lazy = (path: string) => lazyScreen(() => import(`../screens/recovery/${path}`));

const AccountRecoveryChoiceScreen   = lazy('AccountRecoveryChoiceScreen');
const AccountRecoveryScreen         = lazy('AccountRecoveryScreen');
const AccountVerifiedSuccessScreen  = lazy('AccountVerifiedSuccessScreen');
const PassportDataNotFound          = lazy('PassportDataNotFoundScreen');
const RecoverWithPhraseScreen       = lazy('RecoverWithPhraseScreen');
const SaveRecoveryPhraseScreen      = lazy('SaveRecoveryPhraseScreen');

Same pattern applies to the other navigation modules touched in this PR.

app/src/navigation/dev.ts (1)

5-20: Looks good, tiny style nit

Trailing comma after the closing parenthesis of MockDataScreenDeepLink keeps prettier/ESLint happy and avoids noisy diffs when appending props later.

-const MockDataScreenDeepLink = lazyScreen(
-  () => import('../screens/dev/MockDataScreenDeepLink'),
-);
+const MockDataScreenDeepLink = lazyScreen(
+  () => import('../screens/dev/MockDataScreenDeepLink'),
+);
app/src/navigation/settings.ts (1)

7-21: Expose lazyScreen’s generic so screen-prop types aren’t lost
lazyScreen() almost certainly returns React.ComponentType<any>, which silently discards the actual prop contract of each screen. This undermines type-safety for navigation params and can hide run-time bugs.

A minimal tweak inside lazyScreen.tsx keeps the generic intact:

-export function lazyScreen(loader: () => Promise<{ default: React.ComponentType<any> }>) {
-  const Component = React.lazy(loader);
-  return (props: any) => (
+export function lazyScreen<P = {}>(loader: () => Promise<{ default: React.ComponentType<P> }>) {
+  const Component = React.lazy(loader);
+  return (props: P) => (
     <Suspense fallback={<View />}>
       <Component {...props} />
     </Suspense>
   );
}

Benefits:
• IntelliSense & compile-time checks for screen props remain intact.
• No migration required at call-sites.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1892cf7 and 7b876b9.

📒 Files selected for processing (7)
  • app/src/navigation/aesop.ts (1 hunks)
  • app/src/navigation/dev.ts (1 hunks)
  • app/src/navigation/lazyScreen.tsx (1 hunks)
  • app/src/navigation/passport.ts (1 hunks)
  • app/src/navigation/prove.ts (1 hunks)
  • app/src/navigation/recovery.ts (1 hunks)
  • app/src/navigation/settings.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
app/src/**/*.{ts,tsx,js,jsx}

⚙️ CodeRabbit Configuration File

app/src/**/*.{ts,tsx,js,jsx}: Review React Native TypeScript code for:

  • Component architecture and reusability
  • State management patterns
  • Performance optimizations
  • TypeScript type safety
  • React hooks usage and dependencies
  • Navigation patterns

Files:

  • app/src/navigation/passport.ts
  • app/src/navigation/aesop.ts
  • app/src/navigation/recovery.ts
  • app/src/navigation/dev.ts
  • app/src/navigation/lazyScreen.tsx
  • app/src/navigation/settings.ts
  • app/src/navigation/prove.ts
⏰ Context from checks skipped due to timeout of 300000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: analyze-android
  • GitHub Check: analyze-ios
  • GitHub Check: build
🔇 Additional comments (5)
app/src/navigation/aesop.ts (1)

7-11: Switch to lazyScreen looks good

Import replacement is clean, and PassportOnboardingScreen is now wrapped consistently with the new helper. No other changes required here.

app/src/navigation/passport.ts (1)

5-26: LGTM – consistent lazy wrapper adoption

All passport screens now use the shared helper, matching the rest of the navigation layer.

app/src/navigation/settings.ts (1)

5-6: Centralising lazy-loading through lazyScreen is on point
Import looks correct and removes repetitive <Suspense> boilerplate from every navigation file.

app/src/navigation/prove.ts (2)

5-6: Good swap to lazyScreen
Keeps navigation files consistent with the new helper.


17-18: ✅ Import path verified – no update needed
The file app/src/screens/prove/ViewFinderScreen.tsx exists and matches the lazy import, so QRCodeViewFinderScreen will load correctly.

@transphorm
Copy link
Member Author

doesn't work

closing in favor of: #814

@transphorm transphorm closed this Jul 30, 2025
@transphorm transphorm reopened this Jul 30, 2025
@transphorm transphorm closed this Jul 30, 2025
@transphorm transphorm deleted the codex/implement-lazyscreen-and-update-navigation-files branch August 3, 2025 06:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants