Skip to content

Commit

Permalink
module with side-effects was optimized away 🙈
Browse files Browse the repository at this point in the history
  • Loading branch information
etrepum committed May 3, 2024
1 parent 94a6459 commit c2d3246
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
4 changes: 3 additions & 1 deletion packages/lexical-playground/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
*
*/

import './setupEnv';
import './index.css';

import * as React from 'react';
import {createRoot} from 'react-dom/client';

import App from './App';
import setupEnv from './setupEnv';

setupEnv();

// Handle runtime errors
const showErrorOverlay = (err: Event) => {
Expand Down
28 changes: 15 additions & 13 deletions packages/lexical-playground/src/setupEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@

import {DEFAULT_SETTINGS, Settings} from './appSettings';

// override default options with query parameters if any
const urlSearchParams = new URLSearchParams(window.location.search);
export default function setupEnv() {
// override default options with query parameters if any
const urlSearchParams = new URLSearchParams(window.location.search);

for (const param of Object.keys(DEFAULT_SETTINGS)) {
if (urlSearchParams.has(param)) {
try {
const value = JSON.parse(urlSearchParams.get(param) ?? 'true');
DEFAULT_SETTINGS[param as keyof Settings] = Boolean(value);
} catch (error) {
console.warn(`Unable to parse query parameter "${param}"`);
for (const param of Object.keys(DEFAULT_SETTINGS)) {
if (urlSearchParams.has(param)) {
try {
const value = JSON.parse(urlSearchParams.get(param) ?? 'true');
DEFAULT_SETTINGS[param as keyof Settings] = Boolean(value);
} catch (error) {
console.warn(`Unable to parse query parameter "${param}"`);
}
}
}
}

if (DEFAULT_SETTINGS.disableBeforeInput) {
// @ts-expect-error
delete window.InputEvent.prototype.getTargetRanges;
if (DEFAULT_SETTINGS.disableBeforeInput) {
// @ts-expect-error
delete window.InputEvent.prototype.getTargetRanges;
}
}

0 comments on commit c2d3246

Please sign in to comment.