go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/milo/ui/src/main.tsx (about)

     1  // Copyright 2020 The LUCI Authors.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  import { Settings } from 'luxon';
    16  import { configure } from 'mobx';
    17  import { createRoot } from 'react-dom/client';
    18  
    19  import '@/common/api/stackdriver_errors';
    20  import { initDefaultTrustedTypesPolicy } from '@/common/tools/sanitize_html';
    21  import { assertNonNullable } from '@/generic_libs/tools/utils';
    22  import '@/proto_utils/duration_patch';
    23  
    24  import { App } from './App';
    25  import { initUiSW } from './sw/init_sw';
    26  
    27  /**
    28   * Whether the UI service worker should be enabled.
    29   */
    30  declare const ENABLE_UI_SW: boolean;
    31  
    32  if (navigator.serviceWorker && ENABLE_UI_SW) {
    33    initUiSW({ dev: import.meta.env.DEV });
    34  }
    35  
    36  initDefaultTrustedTypesPolicy();
    37  
    38  // TODO(crbug/1347294): encloses all state modifying actions in mobx actions
    39  // then delete this.
    40  configure({ enforceActions: 'never' });
    41  
    42  const container = assertNonNullable(document.getElementById('app-root'));
    43  const root = createRoot(container);
    44  root.render(<App initOpts={{ isDevEnv: import.meta.env.DEV }} />);
    45  
    46  Settings.throwOnInvalid = true;
    47  declare module 'luxon' {
    48    interface TSSettings {
    49      throwOnInvalid: true;
    50    }
    51  }