Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Integrate react-query with PWA-Kit SDK #693

Closed
wants to merge 45 commits into from
Closed
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
6dcdfbc
Demo react-query fetching w/o hard-coded keys on the server-side.
olibrook Jul 26, 2022
d8495de
Actually render fetched data
olibrook Jul 26, 2022
49d3fdc
Server dehydration & client hydration
bendvc Jul 29, 2022
72f19e3
Integrate `react-query` with PWA-Kit SDK
bendvc Aug 8, 2022
fe404c3
Merge branch 'develop' into react-query-ssr-investigation
bendvc Aug 8, 2022
8ad2c5b
Rough-in the `useExpress` hook
bendvc Aug 9, 2022
7fbbfa6
Fix failing tests
bendvc Aug 9, 2022
1ad7bba
Catch prepass errors
bendvc Aug 9, 2022
bc16901
Remove unused query client config
bendvc Aug 9, 2022
567dc3c
Maybe a fix for the issue not finding react query
bendvc Aug 9, 2022
b76b050
Clean up typescript min project.. fix webpack config.
bendvc Aug 9, 2022
4e77acd
Fix unit tests and coverage
bendvc Aug 10, 2022
9fcd04f
Merge branch 'develop' into react-query-ssr-investigation
bendvc Aug 10, 2022
4446a47
Undo changes to webpack
bendvc Aug 10, 2022
4d89149
Merge branch 'react-query-ssr-investigation' of https://github.com/Sa…
bendvc Aug 10, 2022
679bfd2
Add original alias back into webpack config
bendvc Aug 10, 2022
6232bf6
Ensure we don't serialize disabled queries...
bendvc Aug 10, 2022
2f3cb39
Fix conditional fetching of queries.
bendvc Aug 10, 2022
be04bc6
Update CHANGELOG.md
bendvc Aug 11, 2022
4b6e08c
Typo fix
bendvc Aug 11, 2022
05b8277
Playing with adding react-query via hoc
bendvc Aug 15, 2022
71bc126
Commenting and minor changes to function names
bendvc Aug 15, 2022
9716fc8
Fix hoc logic not working with retail template
bendvc Aug 15, 2022
ad10b5b
Fix linting
bendvc Aug 15, 2022
f649776
Split up API functionalities, add rough stacking of API functions
bendvc Aug 17, 2022
bbfd75c
Update react-rendering.js
bendvc Aug 17, 2022
d66d1a1
Clean up.. Make getProps the default... Etc
bendvc Aug 22, 2022
c7a8663
Clean up function and file names
bendvc Aug 23, 2022
8923e63
Change API function name. Change to return promises.
bendvc Aug 24, 2022
bf1a9e6
Refactor routeComponent into withLegaryGetProps, refactor withErrorHa…
bendvc Aug 25, 2022
3f0e8bc
move hoc's into component folder
bendvc Aug 25, 2022
90890d9
Fixed tests for withLegacyGetProps
bendvc Aug 25, 2022
beb3928
Small function name fixes
bendvc Aug 26, 2022
61ce548
Clean up.. linting.. comments.. etc
bendvc Aug 29, 2022
b4c7296
Add tests for with react query hoc
bendvc Aug 29, 2022
a28961f
Fix error handling distinction between render, state, etc
bendvc Aug 29, 2022
3c01239
All getProps tests are passing now.
bendvc Aug 29, 2022
f6d28ac
Re-add useQuery tests
bendvc Aug 29, 2022
05bfa83
Fix errors thrown by withReactRouter data fetching method
bendvc Aug 31, 2022
d0b6221
Fix retail template to use legacy getProps
bendvc Aug 31, 2022
5e3fd6e
Merge branch 'develop' into react-query-ssr-investigation
bendvc Aug 31, 2022
b169daf
Re-build lock files
bendvc Aug 31, 2022
4e5aeb4
Refactor
bendvc Sep 1, 2022
e7147ed
Testing new initStaticContext api
bendvc Sep 6, 2022
76dc4f8
Merge branch 'develop' into react-query-ssr-investigation
bendvc Sep 13, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions packages/pwa-kit-dev/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/pwa-kit-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
},
"devDependencies": {
"@loadable/component": "^5.15.0",
"@tanstack/react-query": "^4.0.10",
"internal-lib-build": "^2.2.0-dev",
"nock": "^13.1.1",
"superagent": "^6.1.0",
Expand Down
1 change: 1 addition & 0 deletions packages/pwa-kit-dev/src/configs/webpack/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const baseConfig = (target) => {
'@loadable/webpack-plugin': findInProjectThenSDK(
'@loadable/webpack-plugin'
),
'@tanstack/react-query': findInProjectThenSDK('@tanstack/react-query'),
'svg-sprite-loader': findInProjectThenSDK('svg-sprite-loader'),
react: findInProjectThenSDK('react'),
'react-router-dom': findInProjectThenSDK('react-router-dom'),
Expand Down
2 changes: 2 additions & 0 deletions packages/pwa-kit-react-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## To be released
- Integrate `react-query`. [#693](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/693)
## v2.1.0 (Jul 05, 2022)
- Remove console logs from route component. [#651](https://github.com/SalesforceCommerceCloud/pwa-kit/pull/651)

Expand Down
30 changes: 30 additions & 0 deletions packages/pwa-kit-react-sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/pwa-kit-react-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@loadable/babel-plugin": "^5.13.2",
"@loadable/server": "^5.15.0",
"@loadable/webpack-plugin": "^5.15.0",
"@tanstack/react-query": "^4.0.10",
bendvc marked this conversation as resolved.
Show resolved Hide resolved
"cross-env": "^5.2.0",
"event-emitter": "^0.3.5",
"glob": "7.1.1",
Expand All @@ -55,6 +56,7 @@
"mkdirp": "^1.0.4",
"prop-types": "^15.6.0",
"pwa-kit-runtime": "^2.2.0-dev",
"react-ssr-prepass": "^1.5.0",
"react-uid": "^2.2.0",
"serialize-javascript": "^6.0.0",
"svg-sprite-loader": "^6.0.11",
Expand Down
2 changes: 2 additions & 0 deletions packages/pwa-kit-react-sdk/setup-jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ jest.mock('pwa-kit-runtime/utils/ssr-config', () => {
'**/*.json'
],
ssrParameters: {
ssrPrepassEnabled: true,
ssrFunctionNodeVersion: '14.x',
proxyConfigs: [
{
Expand All @@ -50,3 +51,4 @@ jest.mock('pwa-kit-runtime/utils/ssr-config', () => {
})
}
})

59 changes: 43 additions & 16 deletions packages/pwa-kit-react-sdk/src/ssr/browser/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,28 @@
import React from 'react'
import ReactDOM from 'react-dom'
import {BrowserRouter as Router} from 'react-router-dom'
import DeviceContext from '../universal/device-context'
import {DeviceContext, ExpressContext} from '../universal/contexts'
import App from '../universal/components/_app'
import AppConfig from '../universal/components/_app-config'
import Switch from '../universal/components/switch'
import {getRoutes, routeComponent} from '../universal/components/route-component'
import {loadableReady} from '@loadable/component'
import {withLegacyGetProps, withLoadableResolver} from '../universal/hocs'
import routes from '../universal/routes'
import Throw404 from '../universal/components/throw-404'

const getRoutes = (locals) => {
let _routes = routes
if (typeof routes === 'function') {
_routes = routes()
}
const allRoutes = [..._routes, {path: '*', component: Throw404}]
return allRoutes.map(({component, ...rest}) => {
return {
component: component ? withLoadableResolver(component) : component,
...rest
}
})
}

/* istanbul ignore next */
export const registerServiceWorker = (url) => {
Expand Down Expand Up @@ -54,7 +70,6 @@ export const start = () => {

// AppConfig.restore *must* come before getRoutes()
AppConfig.restore(locals, window.__PRELOADED_STATE__.__STATE_MANAGEMENT_LIBRARY)
const routes = getRoutes(locals)

// We need to tell the routeComponent HOC when the app is hydrating in order to
// prevent pages from re-fetching data on the first client-side render. The
Expand All @@ -66,25 +81,37 @@ export const start = () => {
// been warned.
window.__HYDRATING__ = true

const WrappedApp = routeComponent(App, false, locals)
// const WrappedApp = routeComponent(App, false, locals)
const WrappedApp = withLegacyGetProps(App)

// NOTE: It's kinda weird how frozn state is loaded in the JSX here. Would be nice if it was
// "added" via or in, the hoc.
let routes = getRoutes(locals)

if (WrappedApp.enhanceRoutes) {
routes = WrappedApp.enhanceRoutes(routes)
}

const error = window.__ERROR__

return Promise.resolve()
.then(() => new Promise((resolve) => loadableReady(resolve)))
.then(() => {
ReactDOM.hydrate(
<Router>
<DeviceContext.Provider value={{type: window.__DEVICE_TYPE__}}>
<AppConfig locals={locals}>
<Switch
error={error}
appState={window.__PRELOADED_STATE__}
routes={routes}
App={WrappedApp}
/>
</AppConfig>
</DeviceContext.Provider>
</Router>,
<ExpressContext.Provider value={{}}>
<Router>
<DeviceContext.Provider value={{type: window.__DEVICE_TYPE__}}>
<AppConfig locals={locals}>
<Switch
error={error}
appState={window.__PRELOADED_STATE__}
routes={routes}
App={WrappedApp}
/>
</AppConfig>
</DeviceContext.Provider>
</Router>
</ExpressContext.Provider>,
rootEl,
() => {
window.__HYDRATING__ = false
Expand Down
Loading