Skip to content

Conversation

@albertoelias-crossmint
Copy link
Collaborator

@albertoelias-crossmint albertoelias-crossmint commented Dec 10, 2025

Description

Fixes a JSON parse error in React Native WebView transport when receiving the "frame-ready" message from the open-signer frame.

Root cause: EventsService.notifyReady() sends "frame-ready" as a plain string, but RNWebViewTransport.handleMessage() was attempting to parse all incoming messages as JSON.

Solution: Check for the "frame-ready" string before attempting JSON parsing and return early since this message doesn't need to be dispatched to listeners.

Test plan

  • Manual testing: Load the email signer in React Native and confirm no JSON parse error appears in logs
  • Verify normal JSON messages still parse and dispatch correctly

Human review checklist

  • Confirm "frame-ready" messages don't need to be dispatched to listeners (the fix silently drops them)
  • Consider if other plain string messages might need similar handling in the future

Package updates

  • @crossmint/client-sdk-rn-window: patch (changeset added)

Link to Devin run: https://app.devin.ai/sessions/884e19777e1d4fa89a507ff8471ed740
Requested by: Alberto Elias (alberto.elias@paella.dev) (@albertoelias-crossmint)

The handleMessage() method was failing when receiving the 'frame-ready'
message from the open-signer frame because it attempted to parse all
messages as JSON. EventsService.notifyReady() sends 'frame-ready' as a
plain string, not JSON.

This fix checks for the 'frame-ready' string before attempting JSON
parsing, preventing the JSON parse error while still correctly handling
all other JSON messages.

Co-Authored-By: Alberto Elias <alberto.elias@paella.dev>
@devin-ai-integration
Copy link
Contributor

Original prompt from Alberto Elias
## Prompt to Fix React Native WebView JSON Parse Error  
  
**Problem:** The React Native WebView transport in `RNWebViewTransport.handleMessage()` fails when receiving the "frame-ready" message from the open-signer frame because it attempts to parse all messages as JSON, but "frame-ready" is sent as a plain string.  
  
**Files to modify:**  
- `packages/client/rn-window/src/transport/RNWebViewTransport.ts` - Update `handleMessage()` method [1-cite-0](#1-cite-0)   
  
**Root cause:**   
- `EventsService.notifyReady()` in open-signer sends "frame-ready" as plain string [1-cite-1](#1-cite-1)   
- `RNWebViewTransport.handleMessage()` tries to parse all messages as JSON [1-cite-2](#1-cite-2)   
  
**Solution:**  
Modify `handleMessage()` to check for "frame-ready" string before attempting JSON parsing:  
  
```typescript  
public handleMessage = (event: WebViewMessageEvent) => {  
    if (!this.isWebView) {  
        try {  
            const data = event.nativeEvent.data;  
              
            // Handle plain string messages like "frame-ready"  
            if (data === "frame-ready") {  
                // Frame is ready, no need to parse as JSON  
                return;  
            }  
              
            const parsedData = JSON.parse(data);  
            this.dispatchToListeners({  
                type: "message",  
                data: parsedData,  
            });  
        } catch (error) {  
            console.error(  
                "[RNTransport RN] Error parsing/handling WebView message:",  
                error instanceof Error ? error.message : String(error),  
                "Raw data:",  
                event.nativeEvent.data  
            );  
        }  
    }  
};  

Testing:
Verify the fix by:

  1. Loading the email signer in React Native
  2. Confirming no JSON parse error in logs
  3. Ensuring normal JSON messages still parse correctly

You only need to look in the following repo: Crossmint/crossmint-sdk

</details>

@changeset-bot
Copy link

changeset-bot bot commented Dec 10, 2025

🦋 Changeset detected

Latest commit: 8fe02c4

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

This PR includes changesets to release 3 packages
Name Type
@crossmint/client-sdk-rn-window Patch
expo-demo Patch
@crossmint/client-sdk-react-native-ui Patch

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

@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@vercel
Copy link

vercel bot commented Dec 10, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
smart-wallet-auth-demo Ignored Ignored Dec 10, 2025 10:34pm

Co-Authored-By: Alberto Elias <alberto.elias@paella.dev>
@albertoelias-crossmint albertoelias-crossmint merged commit fbedd6e into main Dec 10, 2025
4 checks passed
@albertoelias-crossmint albertoelias-crossmint deleted the devin/1765404923-fix-rn-webview-frame-ready branch December 10, 2025 22:51
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.

3 participants