在什么情况下这段代码(来自 React 文档)可能会失败,或者实际上会触发最终的回退条件?

Under what conditions might this piece of code (From the React docs) fail, or rather actually trigger the final fallback condition?

React 文档具有以下代码片段,用于提取 HOC 中组件的名称 (function getDisplayName)。请参阅下面的 getDisplayName 实现。

function withSubscription(WrappedComponent) {
  class WithSubscription extends React.Component {/* ... */}
  WithSubscription.displayName = `WithSubscription(${getDisplayName(WrappedComponent)})`;
  return WithSubscription;
}

function getDisplayName(WrappedComponent) {
  return WrappedComponent.displayName || WrappedComponent.name || 'Component';
}

那么在什么情况下函数会获取不到组件名呢?只是 return 通用字符串 'Component'。如果是这样,有什么方法可以 mitigate/handle 这种情况?

So in what cases will the function fail to get the component name ?

如果给定的组件既没有 displayName 也不是函数或 class 例如使用 React.forwardRef.

创建时

And if so, any ways to mitigate/handle such cases ?

目前没有 public API 这个案例。订阅 https://github.com/facebook/react/issues/14319 以获取有关此问题的更新。