refactor: improve code

This commit is contained in:
tzhangchi 2023-01-02 01:11:19 +08:00 committed by Chi Zhang
parent c93a3ec5e1
commit 42ac45fe15
4 changed files with 20 additions and 25 deletions

View File

@ -6,7 +6,7 @@ import './temporary.css';
import { Logger } from '@toeverything/pathfinder-logger';
import '@fontsource/space-mono';
import '@fontsource/poppins';
import { printBuildInfo } from '../utils/print-build-info';
import '../utils/print-build-info';
import ProviderComposer from '@/components/provider-composer';
import type { PropsWithChildren, ReactElement, ReactNode } from 'react';
import type { NextPage } from 'next';
@ -17,6 +17,7 @@ import { useRouter } from 'next/router';
import { useEffect } from 'react';
import { useAppState } from '@/providers/app-state-provider';
import { PageLoading } from '@/components/loading';
const ThemeProvider = dynamic(() => import('@/providers/themeProvider'), {
ssr: false,
});
@ -34,9 +35,7 @@ type AppPropsWithLayout = AppProps & {
const App = ({ Component, pageProps }: AppPropsWithLayout) => {
const getLayout = Component.getLayout || (page => page);
useEffect(() => {
printBuildInfo();
}, []);
return (
<>
<Logger />

View File

@ -1,6 +1,7 @@
declare global {
interface Window {
CLIENT_APP?: boolean;
__editoVersion?: string;
}
}

View File

@ -12,18 +12,7 @@ type Config = {
const nextConfig = getConfig();
const publicRuntimeConfig: Config = nextConfig.publicRuntimeConfig;
const setAffineAppProperties = () => {
const input = document.createElement('input');
const id = 'editor-version';
if (document.getElementById(id)) {
return;
}
input.value = publicRuntimeConfig.EDITOR_VERSION;
input.type = 'hidden';
input.id = id;
input.setAttribute('data-testid', 'editor-version');
document.body.appendChild(input);
};
const printBuildInfo = () => {
console.group('Build info');
console.log('Project:', publicRuntimeConfig.PROJECT_NAME);
@ -47,8 +36,14 @@ const printBuildInfo = () => {
`https://github.com/toeverything/AFFiNE/tree/${publicRuntimeConfig.COMMIT_HASH}`
);
console.groupEnd();
setAffineAppProperties();
};
export { printBuildInfo };
function setWindowEditorVersion() {
// when it is not SSR
if (typeof window !== 'undefined') {
window.__editoVersion = publicRuntimeConfig.EDITOR_VERSION;
}
}
printBuildInfo();
setWindowEditorVersion();
export {};

View File

@ -9,16 +9,16 @@ test.describe('web console', () => {
// https://playwright.dev/docs/evaluating
// https://github.com/microsoft/playwright/issues/13059
// Get the handle to a specific function.
// const getEditoVersionHandle = await page.evaluate(
// 'window.__getEditoVersion'
// );
//Later on, call this function with some arguments.
// const msg = await getEditoVersionHandle.evaluate((post, args) => post);
// console.log(getEditoVersionHandle);
const documentEditorVersion = await page.inputValue('input#editor-version');
await page.waitForTimeout(500);
const editoVersion = await page.evaluate(
() => (window as any).__editoVersion
);
// const documentEditorVersion = await page.inputValue('input#editor-version');
const pkgEditorVersion = pkg.dependencies['@blocksuite/editor'];
expect(documentEditorVersion).toBe(pkgEditorVersion);
console.log('pkgEditorVersion', pkgEditorVersion);
expect(editoVersion).toBe(pkgEditorVersion);
});
});