Skip to content

[Discover][FieldFormatters] Migrate html field formatters to react #259286

@jughosta

Description

@jughosta

Linking to: https://github.com/elastic/kibana-team/issues/2843

Html field formatters have been around for way too long. It's time to switch to react output for them. Here are the iterative steps which we could follow during this transition as the scope of the changes is quite large.

  1. Introduce reactConvert and use it inside htmlConvert for backward compatibility which additionally provides better security
  2. Migrate the Discover main usages (data grid) to use the react converter directly instead of through the bridge
  3. Continue with migrating the remaining consumers in batches starting with the doc viewer flyout
  4. Remove html as a converter option completely.

Before: HTML-based Field Formatters (Legacy)

graph TD
    A[User Data Value] --> B[Field Formatter]
    B --> C{Content Type?}
    
    C -->|text| D[textConvert]
    C -->|html| E[htmlConvert]
    
    D --> F[Plain Text String]
    E --> G[HTML String with Tags]
    
    G --> H[Consumer Component]
    H --> I["dangerouslySetInnerHTML ⚠️"]
    I --> J[DOM Rendering]
    
    F --> K[Consumer Component]
    K --> L[Safe Text Rendering]
    
    classDef risk fill:#ffcccc,stroke:#ff0000,stroke-width:2px,color:#000000
    classDef safe fill:#ccffcc,stroke:#00aa00,stroke-width:2px,color:#000000
    
    class G,I,J risk
    class F,L safe
Loading

After: React-based Field Formatters with HTML Bridge

graph TD
    A[User Data Value] --> B[Field Formatter]
    B --> C{Content Type?}
    
    C -->|text| D[textConvert]
    C -->|html| E[HTML Bridge]
    C -->|react| F[reactConvert]
    
    D --> G[Plain Text String]
    
    F --> H[React Elements]
    F --> I[checkForMissingValueReact]
    F --> J[getHighlightReact]
    
    I --> K[Styled Missing Value Spans]
    J --> L[Safe Mark Elements]
    
    E --> M[Bridge Logic]
    M --> N{React Output Type?}
    N -->|ReactElement| O[ReactDOM.renderToStaticMarkup]
    N -->|String/Number| P[HTML Escape]
    
    O --> Q[Safe HTML String]
    P --> Q
    
    H --> R[Consumer Component]
    R --> S[Direct React Rendering]
    S --> T[Safe DOM]
    
    Q --> U[Legacy Consumer]
    U --> V["dangerouslySetInnerHTML (Legacy)"]
    V --> W[DOM Rendering]
    
    classDef safe fill:#ccffcc,stroke:#00aa00,stroke-width:2px,color:#000000
    classDef bridge fill:#ccccff,stroke:#0066cc,stroke-width:2px,color:#000000
    classDef legacy fill:#ffffcc,stroke:#cc8800,stroke-width:2px,color:#000000
    
    class H,S,T,K,L safe
    class M,E,O,P,Q bridge
    class U,V,W legacy
Loading

Metadata

Metadata

Assignees

Labels

Feature:FieldFormattersMetaTeam:DataDiscoveryDiscover, search (data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. t//impact:highAddressing this issue will have a high level of impact on the quality/strength of our product.loe:x-largeExtra Large Level of Effort

Type

No fields configured for Meta.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions