-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: #1065 fix loading chunk fail (#1092)
- Loading branch information
NghiaPham
authored
Apr 28, 2020
1 parent
6696946
commit 579d2c5
Showing
31 changed files
with
343 additions
and
49 deletions.
There are no files selected for viewing
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,45 @@ | ||
name: Purge unused assets from s3 | ||
|
||
on: | ||
schedule: | ||
# * is a special character in YAML so you have to quote this string | ||
- cron: '0 0 * * 0' | ||
|
||
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: checks out repository to $GITHUB_WORKSPACE | ||
uses: actions/checkout@v1 | ||
|
||
- name: Setup Node Environement | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 12 | ||
|
||
- name: Cache node modules | ||
id: cache | ||
uses: actions/cache@v1 | ||
with: | ||
path: node_modules | ||
key: build-${{ hashFiles('**/yarn.lock') }} | ||
restore-keys: | | ||
build-${{ hashFiles('**/yarn.lock') }} | ||
- name: Integrate Git credential | ||
uses: webfactory/[email protected] | ||
with: | ||
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
|
||
- name: Install dependencies | ||
run: yarn install | ||
|
||
- name: purge unused assets not belonged to two recent commits | ||
run: yarn handle-purge-unsed-assets-cronjob | ||
|
||
env: | ||
NPM_TOKEN: ${{secrets.NPM_TOKEN}} | ||
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} | ||
AWS_ACCESS_KEY_ID: ${{secrets.AWS_ACCESS_KEY_ID}} | ||
AWS_SECRET_ACCESS_KEY: ${{secrets.AWS_SECRET_ACCESS_KEY}} | ||
AWS_REGION: ${{secrets.AWS_REGION}} |
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
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
30 changes: 30 additions & 0 deletions
30
packages/elements/src/hooks/use-offline-plugin/__tests__/use-offline-plugin.tsx
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,30 @@ | ||
import { renderHook, act } from '@testing-library/react-hooks' | ||
import { useOfflinePLugin } from '../use-offline-plugin' | ||
import * as runtime from 'offline-plugin/runtime' | ||
|
||
jest.mock('offline-plugin/runtime') | ||
|
||
describe('useOfflinePLugin', () => { | ||
it('should call applyUpdate on event onUpdateReady of the service worker', () => { | ||
renderHook(() => useOfflinePLugin()) | ||
const mockedInstallFn = runtime.install as jest.Mock | ||
|
||
act(() => { | ||
mockedInstallFn.mock.calls[0][0].onUpdateReady() | ||
}) | ||
|
||
expect(runtime.applyUpdate).toHaveBeenCalled() | ||
}) | ||
|
||
/* eslint-disable-next-line max-len */ | ||
it('should set isNewVersionAvailable to true when offline-plugin/runtime finish updating service worker with new contents', () => { | ||
const { result } = renderHook(() => useOfflinePLugin()) | ||
const mockedInstallFn = runtime.install as jest.Mock | ||
|
||
act(() => { | ||
mockedInstallFn.mock.calls[0][0].onUpdated() | ||
}) | ||
|
||
expect(result.current.isNewVersionAvailable).toBe(true) | ||
}) | ||
}) |
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 @@ | ||
export * from './use-offline-plugin' |
32 changes: 32 additions & 0 deletions
32
packages/elements/src/hooks/use-offline-plugin/use-offline-plugin.tsx
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,32 @@ | ||
import * as runtime from 'offline-plugin/runtime' | ||
|
||
// this part will be translated by building | ||
runtime.install({ | ||
onUpdateReady: () => { | ||
// Tells to new SW to take control immediately | ||
runtime.applyUpdate() | ||
}, | ||
onUpdated: () => { | ||
// Have to use window to reference since hook can't be referenced in build time | ||
;(window as any).setIsNewVersionAvailable(true) | ||
}, | ||
}) | ||
|
||
import { useState, useEffect } from 'react' | ||
|
||
type UseOfflinePLugin = () => { | ||
isNewVersionAvailable: boolean | ||
} | ||
|
||
export const useOfflinePLugin: UseOfflinePLugin = () => { | ||
const [isNewVersionAvailable, setIsNewVersionAvailable] = useState(false) | ||
useEffect(() => { | ||
;(window as any).setIsNewVersionAvailable = setIsNewVersionAvailable | ||
}) | ||
|
||
useEffect(() => {}) | ||
|
||
return { | ||
isNewVersionAvailable, | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,15 +1,27 @@ | ||
import { PortalProvider } from '@reapit/elements' | ||
import { PortalProvider, useOfflinePLugin, ToastMessage } from '@reapit/elements' | ||
import Router from './router' | ||
import { Provider } from 'react-redux' | ||
import store from './store' | ||
import * as React from 'react' | ||
|
||
const App = () => ( | ||
<Provider store={store.reduxStore}> | ||
<PortalProvider> | ||
<Router /> | ||
</PortalProvider> | ||
</Provider> | ||
) | ||
const App = () => { | ||
const { isNewVersionAvailable } = useOfflinePLugin() | ||
|
||
return ( | ||
<Provider store={store.reduxStore}> | ||
<PortalProvider> | ||
<Router /> | ||
<ToastMessage | ||
preventClose={true} | ||
visible={isNewVersionAvailable} | ||
variant="primary" | ||
onCloseToast={location.reload} | ||
/* eslint-disable-next-line max-len */ | ||
message="A new version is available. Please refresh your browser or click on this notification to receive the latest update." | ||
/> | ||
</PortalProvider> | ||
</Provider> | ||
) | ||
} | ||
|
||
export default App |
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
Oops, something went wrong.