stackflow icon indicating copy to clipboard operation
stackflow copied to clipboard

feat(react): support lazy activity with internal plugin

Open orionmiz opened this issue 7 months ago • 9 comments

orionmiz avatar Aug 01 '25 10:08 orionmiz

Deploying stackflow-demo with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7726c76
Status: ✅  Deploy successful!
Preview URL: https://f4d7e0d0.stackflow-demo.pages.dev
Branch Preview URL: https://lazy-activity.stackflow-demo.pages.dev

View logs

🦋 Changeset detected

Latest commit: 7726c76a70f3087eca117747a42204f433093b47

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@stackflow/react Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Aug 01 '25 10:08 changeset-bot[bot]

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Added support for lazy-loaded activities on React 18–19; navigation now waits for components to load, improving transition reliability.
  • Bug Fixes
    • More predictable behavior when the animation option is undefined, preventing unintended animation states.
  • Chores
    • Prepared a minor release for @stackflow/react.

Walkthrough

Adds a new internal React plugin that detects React.lazy and memoized activity components, pauses navigation while unresolved lazy components load, and conditionally registers the plugin for React major versions 18–19; includes a changeset for a minor @stackflow/react release.

Changes

Cohort / File(s) Change Summary
Lazy Activity Plugin Implementation
integrations/react/src/stable/lazyActivityPlugin.ts
New file: adds lazyActivityPlugin(activityComponentMap) which detects React lazy/memo components, tracks load status, pauses navigation on onBeforePush/onBeforeReplace while awaiting the component's loading promise, and resumes navigation after resolve/reject.
Plugin Registration & Setup
integrations/react/src/stable/stackflow.tsx
Modified plugin initialization: normalizes and types incoming plugins array, imports React version, conditionally appends lazyActivityPlugin(activityComponentMap) when React major version is 18–19, and tightened parsing of animate in action options.
Changeset / Release Note
.changeset/small-rice-listen.md
New changeset added declaring a minor release for @stackflow/react documenting the lazy activity support addition.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Stackflow
    participant LazyPlugin as lazyActivityPlugin
    participant ReactLazy as ReactLazyComponent

    User->>Stackflow: request navigation (push/replace)
    Stackflow->>LazyPlugin: onBeforePush/onBeforeReplace
    LazyPlugin->>ReactLazy: inspect activity component (lazy/memo)
    alt component is lazy and uninitialized
        LazyPlugin->>Stackflow: pause navigation
        LazyPlugin->>ReactLazy: start loading (invoke promise)
        ReactLazy-->>LazyPlugin: promise resolves / rejects
        LazyPlugin->>Stackflow: resume navigation
    else not lazy or already loaded
        LazyPlugin->>Stackflow: allow navigation to continue
    end

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

[!TIP]

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 8823102fff002f8cb556898e9a7e66976083227a and 7726c76a70f3087eca117747a42204f433093b47.

📒 Files selected for processing (1)
  • integrations/react/src/stable/stackflow.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • integrations/react/src/stable/stackflow.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Workers Builds: stackflow-docs
  • GitHub Check: Build all packages
  • GitHub Check: Check whether the written test passes normally
  • GitHub Check: Check the TypeScript typings
  • GitHub Check: Create PR or release packages
✨ Finishing Touches
  • [ ] 📝 Generate Docstrings
🧪 Generate unit tests
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment
  • [ ] Commit unit tests in branch lazy-activity

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

coderabbitai[bot] avatar Aug 01 '25 10:08 coderabbitai[bot]

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
stackflow-docs 7726c76a Commit Preview URL Aug 20 2025, 06:45 AM

@stackflow/demo

yarn add https://pkg.pr.new/@stackflow/[email protected]

commit: 7726c76

pkg-pr-new[bot] avatar Aug 01 '25 10:08 pkg-pr-new[bot]

/oc summarize

orionmiz avatar Aug 11 '25 12:08 orionmiz

This PR adds support for lazy-loaded React components in Stackflow by implementing an internal plugin that handles React.lazy and React.memo components.

Key Changes

New lazy activity plugin (integrations/react/src/stable/lazyActivityPlugin.ts):

  • Detects React.lazy and React.memo components using internal React symbols
  • Pauses navigation during lazy component loading to prevent flicker/errors
  • Handles both onBeforePush and onBeforeReplace events
  • Automatically resumes navigation after component loads (success or failure)

Plugin integration (integrations/react/src/stable/stackflow.tsx):

  • Conditionally registers the plugin only for React 18.x
  • Appends plugin to existing plugin array
  • Uses React version detection to ensure compatibility

Changeset (.changeset/small-rice-listen.md):

  • Documents this as a minor version bump for @stackflow/react
  • No breaking changes to public APIs

Technical Implementation

The plugin works by:

  1. Inspecting activity components for lazy/memo wrappers
  2. Extracting loading promises from React's internal _payload structure
  3. Pausing navigation until promises resolve/reject
  4. Automatically resuming navigation afterward

This is backward-compatible and requires no configuration - it's automatically applied for supported React versions.

Implementing%20lazy%20activity%20support%20for%20Stackflow%20R opencode session  |  github run

opencode-agent[bot] avatar Aug 11 '25 12:08 opencode-agent[bot]

/oc could you review this PR line-by-line via gh api command with gh cli?

orionmiz avatar Aug 20 '25 06:08 orionmiz

undefined is not an object (evaluating '(await client.session.chat({ path: session, body: { providerID, modelID, agent: "build", parts: [ { type: "text", text }, ...files.flatMap((f) => [ { type: "file", mime: f.mime, url: data:${f.mime};base64,${f.content}, filename: f.filename, source: { type: "file", text: { value: f.replacement, start: f.start, end: f.end }, path: f.filename } } ]) ] } })).data.parts')

opencode session  |  github run

opencode-agent[bot] avatar Aug 20 '25 06:08 opencode-agent[bot]