Skip to content

Commit

Permalink
ci: wasm build
Browse files Browse the repository at this point in the history
  • Loading branch information
Gumichocopengin8 committed Aug 10, 2023
1 parent c103449 commit 53b3f6b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 28 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/playwrightCI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ jobs:
with:
node-version: 18
- name: Install dependencies
run: npm ci
run: |
npm ci
npm run build:wasm
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright e2e tests
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/webCI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node-version: [18.x]
node-version: [20.x]

steps:
- uses: actions/checkout@v3
Expand All @@ -42,7 +42,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node-version: [18.x]
node-version: [20.x]

steps:
- uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions web/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@typescript-eslint/explicit-member-accessibility": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/prefer-interface": "off",
"@typescript-eslint/no-empty-function": "off",
"react/react-in-jsx-scope": "off",
"react/self-closing-comp": ["error"],
"react/display-name": "off", // TODO: remove this in the future
Expand Down
2 changes: 1 addition & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"scripts": {
"dev": "next",
"build": "next build",
"build": "npm run build:wasm && next build",
"build:wasm": "wasm-pack build src/web_assembly --target web --release",
"start": "next start -p $PORT",
"lint-app": "eslint './src/**/*.{ts,tsx}'",
Expand Down
46 changes: 23 additions & 23 deletions web/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,39 @@
*/

import React, { useState, useEffect } from 'react';
import { RecoilRoot } from 'recoil';
import { RecoilRoot, useSetRecoilState } from 'recoil';
import { AppProps } from 'next/app';
import { useRouter } from 'next/router';
import Head from 'next/head';
import { CircularProgress } from '@mui/material';
import { css } from '@emotion/react';
import Header from 'components/shared/Header';
import Spinner from 'components/shared/Spinner';
import Footer from 'components/shared/Footer';
import init from 'web_assembly/pkg';
import { isWasmLoadedState } from 'recoil/atoms';

const HiddenComponent = () => {
// hidden compont to load wasm
// This component should be under <RecoilRoot>
const setIsWasmLoaded = useSetRecoilState(isWasmLoadedState);

useEffect(() => {
(async () => {
await init()
.then(() => {
setIsWasmLoaded(true);
})
.catch((err) => {
console.error('wasm error', err);
});
})();
}, [setIsWasmLoaded]);

return <></>;
};

const MyApp = (props: AppProps): JSX.Element => {
const { Component, pageProps } = props;
const [isWasmLoaded, setIsWasmLoaded] = useState<boolean>(false);
const [isLoading, setLoadingState] = useState<boolean>(false);
const router = useRouter();

Expand All @@ -37,29 +56,10 @@ const MyApp = (props: AppProps): JSX.Element => {
}
}, [router]);

useEffect(() => {
(async () => {
await init()
.then(() => {
setIsWasmLoaded(true);
})
.catch((err) => {
console.error('wasm error', err);
});
})();
}, []);

if (!isWasmLoaded) {
return (
<div css={Wrapper}>
<Spinner loadingMessage="Wait for a few moment" />
</div>
);
}

return (
<React.StrictMode>
<RecoilRoot>
<HiddenComponent />
<div css={Wrapper}>
<Head>
<link rel="icon" href="/favicon.png" type="image/png" sizes="32x32" />
Expand Down
7 changes: 6 additions & 1 deletion web/src/recoil/atoms.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { atomFamily } from 'recoil';
import { atomFamily, atom } from 'recoil';
import { crateDataResultsQuery, crateDownloadDataResultsQuery } from 'recoil/selectors';
import { CrateResponse } from 'interfaces/crate';
import { Downloads } from 'interfaces/downloads';
Expand All @@ -12,3 +12,8 @@ export const crateDownloadDataResultsState = atomFamily<Downloads[], string[]>({
key: 'crateDownloadDataResultsState',
default: (crateNames) => crateDownloadDataResultsQuery(crateNames),
});

export const isWasmLoadedState = atom<boolean>({
key: 'isWasmLoaded',
default: false,
});

0 comments on commit 53b3f6b

Please sign in to comment.