<commit_before>/* global twttr */
import React from 'react';
import { connect } from 'react-redux';

import { darkTheme } from '../select-utils';
import ScrollSafe from './scroll-helpers/scroll-safe';
import * as heightCache from './scroll-helpers/size-cache';


const TWEET_RE = /^https?:\/\/twitter\.com\/[^/]+\/status\/([0-9]+)/i;

export function canShowURL(url) {
  return TWEET_RE.test(url);
}

class TwitterPreview extends React.Component {
  elem = React.createRef();

  async embed() {
    await loadTwitterAPI();
    try {
      await twttr.widgets.createTweet(
        getTweetId(this.props.url),
        this.elem.current,
        {
          theme: this.props.darkTheme ? 'dark' : 'light',
          dnt:   true,
        }
      );
    } catch (e) {
      // pass
    }
  }


  componentDidMount() {
    this.embed();
  }

  componentDidUpdate() {<commit_msg>Prevent the Twitter preview multiplication<commit_after>/* global twttr */
import React from 'react';
import { connect } from 'react-redux';

import { darkTheme } from '../select-utils';
import ScrollSafe from './scroll-helpers/scroll-safe';
import * as heightCache from './scroll-helpers/size-cache';


const TWEET_RE = /^https?:\/\/twitter\.com\/[^/]+\/status\/([0-9]+)/i;

export function canShowURL(url) {
  return TWEET_RE.test(url);
}

class TwitterPreview extends React.PureComponent {
  elem = React.createRef();

  async embed() {
    await loadTwitterAPI();
    try {
      this.elem.current.innerHTML = '';
      await twttr.widgets.createTweet(
        getTweetId(this.props.url),
        this.elem.current,
        {
          theme: this.props.darkTheme ? 'dark' : 'light',
          dnt:   true,
        }
      );
    } catch (e) {
      // pass
    }
  }


  componentDidMount() {
    this.embed();
  }

  componentDidUpdate() {
{'fraction_non_alphanumeric': 0.15795266923500276, 'fraction_numerical': 0.002201430930104568, 'mean_word_length': 2.5717092337917484, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5381857', 'n_tokens_mistral': 606, 'n_tokens_neox': 594, 'n_words': 123}