Repository: payloadcms/payload
File: packages/ui/src/forms/fieldSchemasToFormState/renderField.tsx (TypeScript)

Code before:
        throw new MissingEditorProp(fieldConfig) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor
      }

      if (typeof fieldConfig?.editor === 'function') {
        throw new Error('Attempted to access unsanitized rich text editor.')
      }

      if (!fieldConfig.admin) {
        fieldConfig.admin = {}
      }

      if (!fieldConfig.admin.components) {
        fieldConfig.admin.components = {}
      }

      fieldState.customComponents.Field = !mockRSCs ? (
        <WatchCondition path={path}>
          {RenderServerComponent({
            clientProps,
            Component: fieldConfig.editor.FieldComponent,
            importMap: req.payload.importMap,
            serverProps,
          })}
        </WatchCondition>
      ) : (
        'Mock'
      )

      break
    }

    case 'ui': {
      if (fieldConfig?.admin?.components) {
        // Render any extra, untyped components
        for (const key in fieldConfig.admin.components) {
          if (key in defaultUIFieldComponentKeys) {
            continue
          }

          const Component = fieldConfig.admin.components[key]

          fieldState.customComponents[key] = !mockRSCs
            ? RenderServerComponent({
                clientProps,
                Component,
                importMap: req.payload.importMap,
                key: `field.admin.components.${key}`,
                serverProps,
              })
            : 'Mock'
        }

Review comment (security):
See comment - the `sanitizedEditorConfig` is huge. It's worth extracting this lexical-specific prop injection out of the lexical package and do it here in the ui package, in order to avoid the duplication

Code after:
        throw new MissingEditorProp(fieldConfig) // while we allow disabling editor functionality, you should not have any richText fields defined if you do not have an editor
      }

      if (typeof fieldConfig?.editor === 'function') {
        throw new Error('Attempted to access unsanitized rich text editor.')
      }

      if (!fieldConfig.admin) {
        fieldConfig.admin = {}
      }

      if (!fieldConfig.admin.components) {
        fieldConfig.admin.components = {}
      }

      fieldState.customComponents.Field = !mockRSCs ? (
        <WatchCondition path={path}>
          {RenderServerComponent({
            clientProps,
            Component: fieldConfig.editor.FieldComponent,
            importMap: req.payload.importMap,
            serverProps: {
              ...serverProps,
              // Manually inject lexical-specific `sanitizedEditorConfig` server prop, in order to reduce the size of the field schema.
              // Otherwise, the editorConfig would be included twice - once on the top-level, and once as part of the `FieldComponent` server props.
              sanitizedEditorConfig:
                'editorConfig' in fieldConfig.editor ? fieldConfig.editor.editorConfig : undefined,
            },
          })}
        </WatchCondition>
      ) : (
        'Mock'
      )

      break
    }

    case 'ui': {
      if (fieldConfig?.admin?.components) {
        // Render any extra, untyped components
        for (const key in fieldConfig.admin.components) {
          if (key in defaultUIFieldComponentKeys) {
            continue
          }

          const Component = fieldConfig.admin.components[key]

          fieldState.customComponents[key] = !mockRSCs
            ? RenderServerComponent({
                clientProps,
                Component,