mirror of
https://github.com/logto-io/logto.git
synced 2025-03-10 22:22:45 -05:00
refactor(experience): skip non-object messages in native (#5491)
* refactor(experience): skip non-object messages in native * chore: add changeset
This commit is contained in:
parent
213d6f97a4
commit
5a7204571a
2 changed files with 22 additions and 1 deletions
13
.changeset/silent-singers-trade.md
Normal file
13
.changeset/silent-singers-trade.md
Normal file
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
"@logto/experience": patch
|
||||
---
|
||||
|
||||
skip non-object messages in the native environment
|
||||
|
||||
In the `WKWebView` of new iOS versions, some script will constantly post messages to the
|
||||
window object with increasing numbers as the message content ("1", "2", "3", ...).
|
||||
|
||||
Ideally, we should check the source of the message with Logto-specific identifier in the
|
||||
`event.data`; however, this change will result a breaking change for the existing
|
||||
native SDK implementations. Add the `isObject` check to prevent the crazy messages while
|
||||
keeping the backward compatibility.
|
|
@ -1,3 +1,4 @@
|
|||
import { isObject } from '@silverhand/essentials';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
import { isNativeWebview } from '@/utils/native-sdk';
|
||||
|
@ -23,7 +24,14 @@ const useNativeMessageListener = (bypass = false) => {
|
|||
}
|
||||
|
||||
const nativeMessageHandler = (event: MessageEvent) => {
|
||||
if (event.origin === window.location.origin) {
|
||||
// In the `WKWebView` of new iOS versions, some script will constantly post messages to the
|
||||
// window object with increasing numbers as the message content ("1", "2", "3", ...).
|
||||
//
|
||||
// Ideally, we should check the source of the message with Logto-specific identifier in the
|
||||
// `event.data`; however, this change will result a breaking change for the existing
|
||||
// native SDK implementations. Add the `isObject` check to prevent the crazy messages while
|
||||
// keeping the backward compatibility.
|
||||
if (event.origin === window.location.origin && isObject(event.data)) {
|
||||
try {
|
||||
setToast(JSON.stringify(event.data));
|
||||
} catch {}
|
||||
|
|
Loading…
Add table
Reference in a new issue