preactjs / preact

⚛️ Fast 3kB React alternative with the same modern API. Components & Virtual DOM.
https://preactjs.com
MIT License
36.9k stars 1.95k forks source link

support isFragment #4033

Closed cbbfcd closed 1 year ago

cbbfcd commented 1 year ago

As far as I know, there are many projects that use preact to replace react, so it is inevitable that methods such as isFragment will be used in some three-party libraries, but this is not supported by preact. Excuse me, is there any workround? Or consider supporting it?

marvinhagemeister commented 1 year ago

Neither the react package or the react-dom package seem to export a function called isFragment. Can you share more about where you got it from?

If you ran into a problem with a specific library, feel free to post a reproduction case. Happy to look into that.

rschristian commented 1 year ago

Sounds like a react-is sort of thing

cbbfcd commented 1 year ago

@marvinhagemeister @rschristian Thanks for such a quick reply. the problem I encountered is that after replacing react with preact, some third-party libraries, such as ant-design-mobile depend on react-is/isFragment, but this method is not supported by preact/compat, resulting in some components not being able to be run properly, and I believe this problem should be encountered by other developers as well.

rschristian commented 1 year ago

https://github.com/preactjs/preact/issues/3899#issuecomment-1443736906

cbbfcd commented 1 year ago
image

I did some random googling and found that many third libraries support isFragment internally, but for developers, it can be a long wait

cbbfcd commented 1 year ago

For example, I now have the option of raising a pr to ant-design-mobile to be compatible with preact/compat scenarios, but I don't know if they'll accept it, or raising a pr with preact/compat

marvinhagemeister commented 1 year ago

That internalised _isFragment function should pass as is. But seems like tackling #3899 makes sense regardless.

cbbfcd commented 1 year ago

I'm new to preact, Does it make sense to add isFragment code in preact/compat like this?

export function isFragment(element) {
    if (!isValidElement(element)) return false;
    return element.type === preact.Fragment;
}