mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-25 20:00:43 +03:00
Another attempt to conditional load Intl.Segmenter polyfill
This commit is contained in:
parent
c9bbca9e11
commit
c8c96f08ac
5 changed files with 98 additions and 65 deletions
21
src/components/intl-segmenter-suspense.jsx
Normal file
21
src/components/intl-segmenter-suspense.jsx
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
import { shouldPolyfill } from '@formatjs/intl-segmenter/should-polyfill';
|
||||||
|
import { Suspense } from 'preact/compat';
|
||||||
|
import { useEffect, useState } from 'preact/hooks';
|
||||||
|
|
||||||
|
const supportsIntlSegmenter = !shouldPolyfill();
|
||||||
|
|
||||||
|
export default function IntlSegmenterSuspense({ children }) {
|
||||||
|
if (supportsIntlSegmenter) {
|
||||||
|
return <Suspense>{children}</Suspense>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const [polyfillLoaded, setPolyfillLoaded] = useState(false);
|
||||||
|
useEffect(() => {
|
||||||
|
(async () => {
|
||||||
|
await import('@formatjs/intl-segmenter/polyfill-force');
|
||||||
|
setPolyfillLoaded(true);
|
||||||
|
})();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return polyfillLoaded && <Suspense>{children}</Suspense>;
|
||||||
|
}
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { lazy } from 'preact/compat';
|
||||||
import { useLocation, useNavigate } from 'react-router-dom';
|
import { useLocation, useNavigate } from 'react-router-dom';
|
||||||
import { subscribe, useSnapshot } from 'valtio';
|
import { subscribe, useSnapshot } from 'valtio';
|
||||||
|
|
||||||
|
@ -8,16 +9,19 @@ import showToast from '../utils/show-toast';
|
||||||
import states from '../utils/states';
|
import states from '../utils/states';
|
||||||
|
|
||||||
import AccountSheet from './account-sheet';
|
import AccountSheet from './account-sheet';
|
||||||
import Compose from './compose';
|
// import Compose from './compose';
|
||||||
import Drafts from './drafts';
|
import Drafts from './drafts';
|
||||||
import EmbedModal from './embed-modal';
|
import EmbedModal from './embed-modal';
|
||||||
import GenericAccounts from './generic-accounts';
|
import GenericAccounts from './generic-accounts';
|
||||||
|
import IntlSegmenterSuspense from './intl-segmenter-suspense';
|
||||||
import MediaAltModal from './media-alt-modal';
|
import MediaAltModal from './media-alt-modal';
|
||||||
import MediaModal from './media-modal';
|
import MediaModal from './media-modal';
|
||||||
import Modal from './modal';
|
import Modal from './modal';
|
||||||
import ReportModal from './report-modal';
|
import ReportModal from './report-modal';
|
||||||
import ShortcutsSettings from './shortcuts-settings';
|
import ShortcutsSettings from './shortcuts-settings';
|
||||||
|
|
||||||
|
const Compose = lazy(() => import('./compose'));
|
||||||
|
|
||||||
subscribe(states, (changes) => {
|
subscribe(states, (changes) => {
|
||||||
for (const [action, path, value, prevValue] of changes) {
|
for (const [action, path, value, prevValue] of changes) {
|
||||||
// When closing modal, focus on deck
|
// When closing modal, focus on deck
|
||||||
|
@ -36,6 +40,7 @@ export default function Modals() {
|
||||||
<>
|
<>
|
||||||
{!!snapStates.showCompose && (
|
{!!snapStates.showCompose && (
|
||||||
<Modal class="solid">
|
<Modal class="solid">
|
||||||
|
<IntlSegmenterSuspense>
|
||||||
<Compose
|
<Compose
|
||||||
replyToStatus={
|
replyToStatus={
|
||||||
typeof snapStates.showCompose !== 'boolean'
|
typeof snapStates.showCompose !== 'boolean'
|
||||||
|
@ -79,6 +84,7 @@ export default function Modals() {
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
</IntlSegmenterSuspense>
|
||||||
</Modal>
|
</Modal>
|
||||||
)}
|
)}
|
||||||
{!!snapStates.showSettings && (
|
{!!snapStates.showSettings && (
|
||||||
|
|
|
@ -3,11 +3,15 @@ import './index.css';
|
||||||
import './app.css';
|
import './app.css';
|
||||||
|
|
||||||
import { render } from 'preact';
|
import { render } from 'preact';
|
||||||
|
import { lazy } from 'preact/compat';
|
||||||
import { useEffect, useState } from 'preact/hooks';
|
import { useEffect, useState } from 'preact/hooks';
|
||||||
|
|
||||||
import Compose from './components/compose';
|
import IntlSegmenterSuspense from './components/intl-segmenter-suspense';
|
||||||
|
// import Compose from './components/compose';
|
||||||
import useTitle from './utils/useTitle';
|
import useTitle from './utils/useTitle';
|
||||||
|
|
||||||
|
const Compose = lazy(() => import('./components/compose'));
|
||||||
|
|
||||||
if (window.opener) {
|
if (window.opener) {
|
||||||
console = window.opener.console;
|
console = window.opener.console;
|
||||||
}
|
}
|
||||||
|
@ -57,6 +61,7 @@ function App() {
|
||||||
console.debug('OPEN COMPOSE');
|
console.debug('OPEN COMPOSE');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<IntlSegmenterSuspense>
|
||||||
<Compose
|
<Compose
|
||||||
editStatus={editStatus}
|
editStatus={editStatus}
|
||||||
replyToStatus={replyToStatus}
|
replyToStatus={replyToStatus}
|
||||||
|
@ -74,6 +79,7 @@ function App() {
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
</IntlSegmenterSuspense>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import './cloak-mode.css';
|
||||||
|
|
||||||
// Polyfill needed for Firefox < 122
|
// Polyfill needed for Firefox < 122
|
||||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1423593
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=1423593
|
||||||
import '@formatjs/intl-segmenter/polyfill';
|
// import '@formatjs/intl-segmenter/polyfill';
|
||||||
import { render } from 'preact';
|
import { render } from 'preact';
|
||||||
import { HashRouter } from 'react-router-dom';
|
import { HashRouter } from 'react-router-dom';
|
||||||
|
|
||||||
|
|
|
@ -118,9 +118,9 @@ export default defineConfig({
|
||||||
compose: resolve(__dirname, 'compose/index.html'),
|
compose: resolve(__dirname, 'compose/index.html'),
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
manualChunks: {
|
// manualChunks: {
|
||||||
'intl-segmenter-polyfill': ['@formatjs/intl-segmenter/polyfill'],
|
// 'intl-segmenter-polyfill': ['@formatjs/intl-segmenter/polyfill'],
|
||||||
},
|
// },
|
||||||
chunkFileNames: (chunkInfo) => {
|
chunkFileNames: (chunkInfo) => {
|
||||||
const { facadeModuleId } = chunkInfo;
|
const { facadeModuleId } = chunkInfo;
|
||||||
if (facadeModuleId && facadeModuleId.includes('icon')) {
|
if (facadeModuleId && facadeModuleId.includes('icon')) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue