Skip to content

Commit

Permalink
Upgrades, SSR fixes, refactors (#1308)
Browse files Browse the repository at this point in the history
* feat: move next conf to mjs

* refactor: remove old tool conf

* chore: upgrade deps

* chore: try upgrade to react 18

* chore: remove hooks eslint as its provided by another lib

* fix: fresnel so that it runs with react 18

* feat: try out server components and edge
  • Loading branch information
ob6160 committed Mar 29, 2022
1 parent dceb767 commit 3e106bb
Show file tree
Hide file tree
Showing 15 changed files with 280 additions and 217 deletions.
3 changes: 1 addition & 2 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"next/core-web-vitals",
"plugin:@typescript-eslint/recommended",
"plugin:jsx-a11y/recommended",
"plugin:functional/no-mutations",
"plugin:react-hooks/recommended"
"plugin:functional/no-mutations"
],
"parserOptions": {
"ecmaFeatures": {
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16
16.13
2 changes: 0 additions & 2 deletions .yarnrc

This file was deleted.

6 changes: 0 additions & 6 deletions codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@ generates:
importDocumentNodeExternallyFrom: ./graphql
reactApolloVersion: 3
withHooks: true
# withHOC: false
# excludePatterns: 'getComments'
# excludePatternsOptions: 'i'
# customDataIdFromObjectName: 'test'
# customDataIdFromObjectImport: 'abc'
apolloClientInstanceImport: './withApollo'
# apolloStateKey: '__APOLLO_STATE__'
preset: import-types
presetConfig:
typesPath: ./graphql
Expand Down
3 changes: 3 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ module.exports = {
// !! WARN !!
ignoreBuildErrors: true,
},
experimental: {
runtime: 'edge',
},
async rewrites() {
return [
// Map lng-lat routes to a single page
Expand Down
19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@
"leaflet.markercluster": "1.5.3",
"lodash": "4.17.21",
"micro": "9.3.4",
"mongoose": "6.2.8",
"mongoose": "6.2.9",
"mongoose-paginate": "5.0.3",
"next": "12.1.1",
"next-plausible": "3.1.6",
"next": "^12.1.2",
"next-plausible": "3.1.7",
"ngeohash": "0.6.3",
"prop-types": "15.8.1",
"query-string": "7.1.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"react": "18.0.0",
"react-dom": "18.0.0",
"react-hook-form": "7.28.1",
"react-leaflet": "3.2.5",
"react-leaflet-control": "2.1.2",
Expand All @@ -92,22 +92,21 @@
"@types/jest": "27.4.1",
"@types/leaflet": "1.7.9",
"@types/leaflet.markercluster": "^1.4.6",
"@types/lodash": "4.14.180",
"@types/lodash": "4.14.181",
"@types/ngeohash": "0.6.4",
"@types/node": "17.0.23",
"@types/react": "17.0.43",
"@types/react-dom": "17.0.14",
"@types/react-leaflet": "2.8.2",
"@types/styled-system": "5.1.15",
"@typescript-eslint/eslint-plugin": "5.16.0",
"@typescript-eslint/parser": "5.16.0",
"@typescript-eslint/eslint-plugin": "5.17.0",
"@typescript-eslint/parser": "5.17.0",
"cli-progress": "3.10.0",
"dotenv": "16.0.0",
"eslint": "8.12.0",
"eslint-config-next": "12.1.1",
"eslint-config-next": "12.1.2",
"eslint-plugin-functional": "4.2.0",
"eslint-plugin-jsx-a11y": "6.5.1",
"eslint-plugin-react-hooks": "4.3.0",
"geojson-precision": "1.0.0",
"graphql-codegen-apollo-next-ssr": "1.7.1",
"husky": "7.0.4",
Expand Down
3 changes: 1 addition & 2 deletions src/components/EntryForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ const Section: React.FC<{

<Box as="tbody" pl={[2, 4]}>
{questions.map(({ field, label, value, onChange }) => {
console.log(field, value);
return (
<Box as="tr" key={field} mt={3} onChange={onChange}>
<Box as="td" width="52%" pl={[2, 4]}>
Expand Down Expand Up @@ -241,7 +240,7 @@ const EntryForm = ({ title, loo, children, ...props }) => {
let transformed = pick(data, dirtyFieldNames);

transformed = omit(transformed, ['geometry']);
console.log(data.geometry);

// eslint-disable-next-line functional/immutable-data
transformed.noPayment = data.isFree;

Expand Down
9 changes: 6 additions & 3 deletions src/components/Logo/Logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import Image from 'next/image';
import logo from './logo.svg';
import Box from '../Box';

const Logo = (props) => (
<Box width="150px">
const Logo = React.forwardRef<HTMLDivElement>((props, ref) => (
<Box width="150px" ref={ref}>
<Image
src={logo}
alt="The Great British Toilet Map"
layout="responsive"
{...props}
/>
</Box>
);
));

// eslint-disable-next-line functional/immutable-data
Logo.displayName = 'Logo';

export default Logo;
5 changes: 3 additions & 2 deletions src/components/Media.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createMedia } from '@artsy/fresnel';

import theme from '../theme';

const { MediaContextProvider, Media } = createMedia({
const GBPTMMedia = createMedia({
breakpoints: {
sm: 0,
md: parseInt(theme.breakpoints[0]),
Expand All @@ -11,4 +11,5 @@ const { MediaContextProvider, Media } = createMedia({
},
});

export { MediaContextProvider, Media };
export const mediaStyle = GBPTMMedia.createMediaStyle();
export const { MediaContextProvider, Media } = GBPTMMedia;
82 changes: 48 additions & 34 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,45 +11,59 @@ import Header from '../components/Header';
import Footer from '../components/Footer';
import globalStyles from '../globalStyles';
import theme from '../theme';
import { useEffect, useState } from 'react';

const App = ({ Component, pageProps }) => (
<PlausibleProvider
domain="toiletmap.org.uk"
customDomain="https://stats.toiletmap.org.uk/"
>
<UserProvider>
<MapStateProvider>
<ThemeProvider theme={theme}>
<MediaContextProvider>
{globalStyles}
const App = ({ Component, pageProps }) => {
const [disableDynamicMediaQueries, setDisableDynamicMediaQueries] =
useState(true);

<Box display="flex" flexDirection="column" height="100%">
<Header>
<Footer />
</Header>
// Only enable dynamic media queries once the document has been hydrated.
useEffect(() => {
if (typeof window !== 'undefined') {
setDisableDynamicMediaQueries(false);
}
}, [disableDynamicMediaQueries]);

<Box position="relative" display="flex" flexGrow={1}>
<Box
as="main"
flexGrow={1}
// support screen readers in ie11
role="main"
>
<Component {...pageProps} />
</Box>
</Box>
return (
<PlausibleProvider
domain="toiletmap.org.uk"
customDomain="https://stats.toiletmap.org.uk/"
>
<UserProvider>
<MapStateProvider>
<ThemeProvider theme={theme}>
<MediaContextProvider
disableDynamicMediaQueries={disableDynamicMediaQueries}
>
{globalStyles}

<Box mt="auto">
<Media greaterThan="sm">
<Box display="flex" flexDirection="column" height="100%">
<Header>
<Footer />
</Media>
</Header>
<Box position="relative" display="flex" flexGrow={1}>
<Box
as="main"
flexGrow={1}
// support screen readers in ie11
role="main"
>
<Component {...pageProps} />
</Box>
</Box>

<Box mt="auto">
<Media greaterThan="sm">
<Footer />
</Media>
</Box>
</Box>
</Box>
</MediaContextProvider>
</ThemeProvider>
</MapStateProvider>
</UserProvider>
</PlausibleProvider>
);
</MediaContextProvider>
</ThemeProvider>
</MapStateProvider>
</UserProvider>
</PlausibleProvider>
);
};

export default App;
22 changes: 22 additions & 0 deletions src/pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Html, Head, Main, NextScript } from 'next/document';
import { mediaStyle } from '../components/Media';

const Document = () => {
return (
<Html>
<Head>
<style
id="media-bps"
type="text/css"
dangerouslySetInnerHTML={{ __html: mediaStyle }}
/>
</Head>
<body>
<Main />
<NextScript />
</body>
</Html>
);
};

export default Document;
2 changes: 1 addition & 1 deletion src/pages/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const server = new ApolloServer({
}
}
} catch (e) {
console.log(e);
console.error(e);
}
return {
user,
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"jsxImportSource": "@emotion/react",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "next.config.js"],
"exclude": ["node_modules"]
}
12 changes: 0 additions & 12 deletions typestat.json

This file was deleted.

0 comments on commit 3e106bb

Please sign in to comment.