-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(artusx-react): support service worker
- Loading branch information
Showing
23 changed files
with
535 additions
and
589 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
lib | ||
|
||
# test | ||
test-results | ||
playwright-report |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { defineConfig } from '@playwright/test'; | ||
|
||
export default defineConfig({ | ||
// Folder for test artifacts such as screenshots, videos, traces, etc. | ||
outputDir: 'test-results', | ||
|
||
// reporter: 'html', | ||
reporter: [ | ||
['list'], | ||
['html', { open: 'never' }], | ||
['json', { outputFile: 'playwright-report/test-results.json' }], | ||
], | ||
|
||
// path to the global setup files. | ||
// globalSetup: require.resolve('./global-setup'), | ||
|
||
// path to the global teardown files. | ||
// globalTeardown: require.resolve('./global-teardown'), | ||
|
||
// Each test is given 30 seconds. | ||
timeout: 30000, | ||
// use: { | ||
// headless: false, | ||
// viewport: { width: 1280, height: 720 }, | ||
// ignoreHTTPSErrors: true, | ||
// video: 'on-first-retry', | ||
// }, | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from 'react'; | ||
import { NavLink } from 'react-router-dom'; | ||
import viteLogo from '@/assets/vite.svg'; | ||
import reactLogo from '@/assets/react.svg'; | ||
import './index.css'; | ||
|
||
const Side: React.FC<{}> = () => { | ||
return ( | ||
<> | ||
<div className="info"> | ||
<a href="https://vitejs.dev" target="_blank"> | ||
<img src={viteLogo} className="logo" alt="Vite logo" /> | ||
</a> | ||
<a href="https://react.dev" target="_blank"> | ||
<img src={reactLogo} className="logo react" alt="React logo" /> | ||
</a> | ||
|
||
<h1>Vite + React + PWA</h1> | ||
<p className="read-the-docs">Click on the Vite and React logos to learn more</p> | ||
</div> | ||
|
||
<nav className="nav"> | ||
<NavLink | ||
to="/" | ||
className={({ isActive, isPending }) => (isPending ? 'pending' : isActive ? 'active' : '')} | ||
> | ||
Home | ||
</NavLink> | ||
<NavLink | ||
to="/info" | ||
className={({ isActive, isPending }) => (isPending ? 'pending' : isActive ? 'active' : '')} | ||
> | ||
Info | ||
</NavLink> | ||
</nav> | ||
</> | ||
); | ||
}; | ||
|
||
export default Side; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
import React from 'react'; | ||
import { createRoot, hydrateRoot } from 'react-dom/client'; | ||
import App from './App.tsx'; | ||
import './index.css'; | ||
import { useMeasure } from './hooks/useMeasure'; | ||
import Rooter from './rooter'; | ||
import './global.css'; | ||
|
||
const container = document.getElementById('root'); | ||
|
||
const FullApp = () => ( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode> | ||
); | ||
const Root: React.FC<{}> = () => { | ||
useMeasure('reactMeasure', 'html.render', 'react.root'); | ||
return <Rooter />; | ||
}; | ||
|
||
if (import.meta.hot || !container?.innerText) { | ||
performance.mark('react.createRoot'); | ||
const root = createRoot(container!); | ||
root.render(<FullApp />); | ||
root.render(<Root />); | ||
} else { | ||
hydrateRoot(container!, <FullApp />); | ||
performance.mark('react.hydrateRoot'); | ||
hydrateRoot(container!, <Root />); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
import React from 'react'; | ||
import ReactDOMServer from 'react-dom/server'; | ||
import App from './App.tsx'; | ||
import './index.css'; | ||
import Rooter from './rooter'; | ||
import './global.css'; | ||
|
||
export function render(url?: string) { | ||
console.log('rendering', url); | ||
return ReactDOMServer.renderToString( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode> | ||
); | ||
return ReactDOMServer.renderToString(<Rooter />); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { useEffect } from 'react'; | ||
|
||
const clearMarks = (mark: string) => { | ||
performance.getEntriesByName(mark, 'mark').forEach((entry) => { | ||
console.debug('clearMarks.entry', entry.name); | ||
performance.clearMarks(entry.name); | ||
}); | ||
}; | ||
|
||
const clearMeasures = (measure: string) => { | ||
performance.getEntriesByName(measure, 'measure').forEach((entry) => { | ||
console.debug('clearMeasures.entry', entry.name); | ||
performance.clearMeasures(entry.name); | ||
}); | ||
}; | ||
|
||
export const useMeasure = (name: string, start: string, end: string) => { | ||
if (!name || !start || !end) { | ||
return; | ||
} | ||
|
||
clearMarks(end); | ||
|
||
console.debug('useMeasure.mark', end); | ||
performance.mark(end); | ||
|
||
useEffect(() => { | ||
const measure = () => { | ||
const customMeasure = performance.measure(name, start, end); | ||
console.debug('useMeasure.customMeasure', customMeasure.name, customMeasure.duration, customMeasure); | ||
}; | ||
|
||
measure(); | ||
|
||
return () => { | ||
clearMarks(start); | ||
clearMarks(end); | ||
clearMeasures(name); | ||
}; | ||
}, []); | ||
|
||
return {}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { useMeasure } from '../hooks/useMeasure'; | ||
import Counter from '../components/Counter'; | ||
|
||
function Home() { | ||
useMeasure('homeMeasure', 'root.render', 'home.render'); | ||
|
||
return ( | ||
<div> | ||
<h1>Home</h1> | ||
<Counter /> | ||
</div> | ||
); | ||
} | ||
|
||
export default Home; |
Oops, something went wrong.