Skip to content

Web: Fix crash that happens when the app receives an unknown message#15087

Open
laurent22 wants to merge 2 commits intodevfrom
webapp_unknown_message
Open

Web: Fix crash that happens when the app receives an unknown message#15087
laurent22 wants to merge 2 commits intodevfrom
webapp_unknown_message

Conversation

@laurent22
Copy link
Copy Markdown
Owner

For example, extensions can send messages which would crash the app because those messages may not have the .kind property

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f2c4797e-5f35-4ddf-b29e-06e5527cfaf9

📥 Commits

Reviewing files that changed from the base of the PR and between 7b5111d and 0b7e43c.

📒 Files selected for processing (1)
  • packages/app-mobile/utils/ipc/RNToWebViewMessenger.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/app-mobile/utils/ipc/RNToWebViewMessenger.ts

📝 Walkthrough

Walkthrough

The RNToWebViewMessenger.onWebViewMessage method now normalises incoming event payloads into a single data value (using event.nativeEvent.data directly when canUseOptimizedPostMessage is true, otherwise attempting JSON.parse). It logs and returns on parse failure, and only forwards messages when data is a non-null object with a string kind property; logging uses a module-level logger.

Changes

Cohort / File(s) Summary
Message validation and logging
packages/app-mobile/utils/ipc/RNToWebViewMessenger.ts
Normalises incoming payload into data (optimised postMessage vs JSON.parse), catches and logs JSON parse failures and returns early, validates data is a non-null object with a string kind before calling this.onMessage(data), and introduces a module-level Logger.create('RNToWebViewMessenger') instance for logs.

Suggested labels

mobile, bug


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Pr Description Must Follow Guidelines ❌ Error The pull request description lacks a high-level explanation of the solution approach and omits test plan or verification steps, violating Joplin contribution guidelines. Expand the PR description to include the solution approach, concrete test plan, and verification steps to make it self-contained and reviewable.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: fixing a crash caused by unknown messages, which aligns with the changeset that adds validation and error handling for incoming payloads.
Description check ✅ Passed The description is directly related to the changeset, explaining the specific problem (extensions sending messages without .kind property) that the changes address.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch webapp_unknown_message

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot added bug It's a bug mobile All mobile platforms labels Apr 13, 2026
Copy link
Copy Markdown
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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/app-mobile/utils/ipc/RNToWebViewMessenger.ts`:
- Around line 47-52: The JSON.parse call in RNToWebViewMessenger.ts can throw
for non-JSON payloads before the kind/type guard runs; wrap the non-web branch
parse in a try/catch (or otherwise validate the string) so malformed JSON
doesn't crash: when canUseOptimizedPostMessage is false, attempt
JSON.parse(event.nativeEvent.data) inside a try block, on failure log the raw
payload via logger.info or logger.warn and return early, and only call
this.onMessage(data) when parsing succeeded and the existing typeof data ===
'object' && data !== null && typeof data.kind === 'string' check passes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 07b91077-9efb-4222-9992-3c0f48ff313b

📥 Commits

Reviewing files that changed from the base of the PR and between fc212d0 and 7b5111d.

📒 Files selected for processing (1)
  • packages/app-mobile/utils/ipc/RNToWebViewMessenger.ts

Comment thread packages/app-mobile/utils/ipc/RNToWebViewMessenger.ts Outdated
@laurent22 laurent22 added the v3.7 label Apr 14, 2026
@coderabbitai coderabbitai Bot removed bug It's a bug mobile All mobile platforms labels Apr 14, 2026
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.

1 participant