UNPKG

@atlaskit/renderer

Version:
44 lines (42 loc) 1.59 kB
/* eslint-disable jsdoc/require-jsdoc */ import React, { useMemo } from 'react'; import { fg } from '@atlaskit/platform-feature-flags'; import { useAnalyticsEvents } from '@atlaskit/analytics-next'; import { FabricChannel } from '@atlaskit/analytics-listeners'; import { EVENT_TYPE } from '@atlaskit/editor-common/analytics'; import RendererActions from '../../actions/index'; export const RendererContext = /*#__PURE__*/React.createContext(new RendererActions()); export function RendererActionsContext({ children, context }) { const { createAnalyticsEvent } = useAnalyticsEvents(); const actions = useMemo(() => new RendererActions(true), []); // Remove this eventually when root cause is assessed if (React.Children.count(children) > 1 && fg('confluence_frontend_fix_view_page_slo')) { // Send event when we get more than 1 child try { throw new Error('Too many children'); } catch (e) { const { stack } = e; createAnalyticsEvent({ eventType: EVENT_TYPE.TRACK, action: 'rendered', actionSubject: 'multipleChildren', actionSubjectId: 'rendererActionsContext', attributes: { numChildren: React.Children.count(children), stackTrace: stack } }).fire(FabricChannel.editor); } } return /*#__PURE__*/React.createElement(RendererContext.Provider, { value: context || actions }, fg('confluence_frontend_fix_view_page_slo') ? React.Children.only(children) : children); } export const RendererActionsContextConsumer = RendererContext.Consumer;