<commit_before>/* global __DEV__ HAS_CLIENT_LOADING ROC_CLIENT_LOADING ROC_PATH HAS_REDUX_REDUCERS */

import React from 'react';
import ReactDOM from 'react-dom';

import Router from 'react-router/lib/Router';
import useRouterHistory from 'react-router/lib/useRouterHistory';
import { createHistory } from 'history';

import debug from 'debug';

import { RedialContext } from 'react-router-redial';
import { rocConfig } from '../shared/universal-config';

const clientDebug = debug('roc:client');

const basename = ROC_PATH === '/' ? '' : ROC_PATH;

/**
 * Client entry point for React applications.
 *
 * @example
 * import { createClient } from 'roc-web-react/app/client';
 *
 * const server = createClient({
 *     createRoutes: routes,
 *     createStore: store,
 *     mountNode: 'application'
 * });
 *
 * @param {rocClientOptions} options - Options for the client
 */
export default function createClient({ createRoutes, createStore, mountNode }) {
    if (!createRoutes) {
        throw new Error(`createRoutes needs to be defined`);
    }

    if (!mountNode) {
        throw new Error(`mountNode needs to be defined`);
    }

    if (rocConfig) {
        debug.enable(rocConfig.runtime.debug.client);
    }

    if (__DEV__ && rocConfig.dev.a11y) {
        if (rocConfig.runtime.ssr) {
            clientDebug('You will see a "Warning: React attempted to reuse markup in a container but the checksum was' +
                ' invalid." message. That\'s because a11y is enabled.');
        }

        require('react-a11y')(React, {
            ReactDOM,
            // These needs to be added for Redux Devtools to be ignored by A11Y
            filterFn: (name) => [
                'LogMonitorButton',
                'LogMonitorAction',
                'JSONValueNode',
                'JSONNestedNode',
                'JSONArrow'
            ].indexOf(name) === -1
        });
    }

    const render = () => {
        const node = document.getElementById(mountNode);

        let history = useRouterHistory(createHistory)({
            basename
        });

        let initialLoading = null;
        if (HAS_CLIENT_LOADING) {
            initialLoading = require(ROC_CLIENT_LOADING).default;
        }

        let routes;
        let locals = {};
        let createComponent = [(component) => component];
        let createDevComponent = [(component) => component];

        if (HAS_REDUX_REDUCERS && createStore) {
            const { Provider } = require('react-redux');
            const { syncHistoryWithStore } = require('react-router-redux');

            const store = createStore(history, window.FLUX_STATE);
            history = syncHistoryWithStore(history, store);

            routes = createRoutes(store);<commit_msg>Only sync the url using react-router-redux if the browser supports it<commit_after>/* global __DEV__ HAS_CLIENT_LOADING ROC_CLIENT_LOADING ROC_PATH HAS_REDUX_REDUCERS */

import React from 'react';
import ReactDOM from 'react-dom';

import Router from 'react-router/lib/Router';
import useRouterHistory from 'react-router/lib/useRouterHistory';
import { createHistory } from 'history';
import { supportsHistory } from 'history/lib/DOMUtils';

import debug from 'debug';

import { RedialContext } from 'react-router-redial';
import { rocConfig } from '../shared/universal-config';

const clientDebug = debug('roc:client');

const basename = ROC_PATH === '/' ? '' : ROC_PATH;

/**
 * Client entry point for React applications.
 *
 * @example
 * import { createClient } from 'roc-web-react/app/client';
 *
 * const server = createClient({
 *     createRoutes: routes,
 *     createStore: store,
 *     mountNode: 'application'
 * });
 *
 * @param {rocClientOptions} options - Options for the client
 */
export default function createClient({ createRoutes, createStore, mountNode }) {
    if (!createRoutes) {
        throw new Error(`createRoutes needs to be defined`);
    }

    if (!mountNode) {
        throw new Error(`mountNode needs to be defined`);
    }

    if (rocConfig) {
        debug.enable(rocConfig.runtime.debug.client);
    }

    if (__DEV__ && rocConfig.dev.a11y) {
        if (rocConfig.runtime.ssr) {
            clientDebug('You will see a "Warning: React attempted to reuse markup in a container but the checksum was' +
                ' invalid." message. That\'s because a11y is enabled.');
        }

        require('react-a11y')(React, {
            ReactDOM,
            // These needs to be added for Redux Devtools to be ignored by A11Y
            filterFn: (name) => [
                'LogMonitorButton',
                'LogMonitorAction',
                'JSONValueNode',
                'JSONNestedNode',
                'JSONArrow'
            ].indexOf(name) === -1
        });
    }

    const render = () => {
        const node = document.getElementById(mountNode);

        let history = useRouterHistory(createHistory)({
            basename
        });

        let initialLoading = null;
        if (HAS_CLIENT_LOADING) {
            initialLoading = require(ROC_CLIENT_LOADING).default;
        }

        let routes;
        let locals = {};
        let createComponent = [(component) => component];
        let createDevComponent = [(component) => component];

        if (HAS_REDUX_REDUCERS && createStore) {
            const { Provider } = require('react-redux');
            const { syncHistoryWithStore } = require('react-router-redux');

            const store = createStore(history, window.FLUX_STATE);
            history = syncHistoryWithStore(history, store, {
                // We do not want to use adjustUrlOnReplay if the browser does
                // not support the history API with pushState since this can lead
                // to redirect loops https://github.com/reactjs/react-router-redux/issues/285
                adjustUrlOnReplay: supportsHistory()
            });

            routes = createRoutes(store);
{'fraction_non_alphanumeric': 0.1114107534131131, 'fraction_numerical': 0.0035395246923984494, 'mean_word_length': 2.4320416425679583, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 1, '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': '6815127', 'n_tokens_mistral': 1666, 'n_tokens_neox': 1607, 'n_words': 441}