Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/slate-dom/src/utils/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export const IS_UC_MOBILE =
export const IS_WECHATBROWSER =
typeof navigator !== 'undefined' &&
/.*Wechat/.test(navigator.userAgent) &&
!/.*MacWechat/.test(navigator.userAgent) // avoid lookbehind (buggy in safari < 16.4)

!/.*MacWechat/.test(navigator.userAgent) && // avoid lookbehind (buggy in safari < 16.4)
(IS_CHROME ? IS_CHROME_LEGACY : true) // wechat and low chrome is real wechat
Copy link
Contributor

@12joan 12joan Jul 5, 2025

Choose a reason for hiding this comment

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

This is equivalent to !IS_CHROME || IS_CHROME_LEGACY. If that's what you intended, can we replace the condition with this?

Is it possible for the !IS_CHROME case to arise if the user agent contains Wechat (i.e. are there WeChat versions that don't mention Chrome in their user agents)? If not, we can simplify to IS_CHROME_LEGACY.

You said in the PR description:

Now the latest WeChat browser for Windows has used a newer version of Chrome

So it sounds like IS_WECHATBROWSER shouldn't be dependent on IS_CHROME_LEGACY. Do we actually want to rename this constant IS_WECHAT_LEGACY?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The main concern is that the old version still uses the lower version of the Chrome kernel, so I added a bottom-line judgment. In fact, it is not necessary for the latest version at present.
Now UA:

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 NetType/WIFI MicroMessenger/7.0.20.1781(0x6700143B) WindowsWechat(0x63090c33) XWEB/13639 Flue

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense. It sounds like the best thing to do would be to rename the constant to IS_WECHAT_LEGACY to clarify that special behaviour is only needed on the old version, and to simplify the boolean condition.

If the old version's user agent always contains the string Chrome, then && IS_CHROME_LEGACY should be sufficient; no need to check IS_CHROME.

Otherwise, I would recommend && (!IS_CHROME || IS_CHROME_LEGACY).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right, this looks more elegant, I will modify it.

// Check if DOM is available as React does internally.
// https://github.com/facebook/react/blob/master/packages/shared/ExecutionEnvironment.js
export const CAN_USE_DOM = !!(
Expand Down