-
Notifications
You must be signed in to change notification settings - Fork 29
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
Introduce app-root #5423
Introduce app-root #5423
Changes from 8 commits
28c39fc
a6c405f
ef0cbcc
1646fca
495aa02
cc8bf03
75180ee
c6355b1
b258ac7
afcb090
9ad5bad
41f1913
593ad9b
f196da1
1c02628
98dc8e1
eaef472
0647d78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# next.js | ||
/.next/ | ||
/out/ | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# app-root | ||
|
||
### Node | ||
```sh | ||
yarn dev | ||
``` | ||
or | ||
|
||
```sh | ||
yarn build | ||
yarn start | ||
``` |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this file do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, is it a Visual Studio thing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct! I'll delete this file There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Uh oh, this file is actually responsible for resolving paths. When I delete it there's an error:
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"paths": { | ||
"@/*": ["./src/*"] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = {} | ||
|
||
module.exports = nextConfig | ||
goplayoutside3 marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "@zooniverse/app-root", | ||
"description": "", | ||
"license": "Apache-2.0", | ||
"author": "Zooniverse <contact@zooniverse.org> (https://www.zooniverse.org/)", | ||
"version": "0.1.0", | ||
"private": true, | ||
"scripts": { | ||
"dev": "next dev", | ||
"build": "next build", | ||
"start": "next start", | ||
"lint": "next lint" | ||
}, | ||
"dependencies": { | ||
"@zooniverse/async-states": "~0.0.1", | ||
"@zooniverse/grommet-theme": "~3.1.1", | ||
"@zooniverse/panoptes-js": "~0.4.1", | ||
"@zooniverse/react-components": "~1.6.1", | ||
"grommet": "~2.33.2", | ||
"grommet-icons": "~4.11.0", | ||
"next": "13.5.2", | ||
goplayoutside3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"react": "18.2.0", | ||
"react-dom": "18.2.0", | ||
goplayoutside3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"styled-components": "^5.3.10" | ||
goplayoutside3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
"engines": { | ||
"node": ">=18.13" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function AboutPage() { | ||
return ( | ||
<div> | ||
<p>This is lib-content-pages</p> | ||
</div> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function UserGroupPage() { | ||
return ( | ||
<div> | ||
<p>This is lib-user</p> | ||
</div> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import RootLayout from '@/components/RootLayout' | ||
import StyledComponentsRegistry from './style-registry' | ||
|
||
export const metadata = { | ||
title: 'Zooniverse', | ||
description: 'People-powered Research' | ||
} | ||
|
||
export default function NextLayout({ children }) { | ||
return ( | ||
<html lang='en'> | ||
<body style={{ margin: 0 }}> | ||
goplayoutside3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<StyledComponentsRegistry> | ||
<RootLayout>{children}</RootLayout> | ||
</StyledComponentsRegistry> | ||
</body> | ||
goplayoutside3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</html> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function RootLoading() { | ||
return ( | ||
<p>Loading...</p> | ||
) | ||
} | ||
|
||
export default RootLoading |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function HomePage() { | ||
return ( | ||
<div> | ||
<p>This is the zooniverse.org home page</p> | ||
</div> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function ProjectPage() { | ||
return ( | ||
<div> | ||
<p>This is lib-project</p> | ||
</div> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use client' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting, so the server sends an unstyled page to the browser, then styles are built in the client? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or maybe not. The downloaded HTML includes an inline stylesheet. Vendor prefixes can definitely be removed here. If we could move all this into an external CSS file, that would cost us less to build and serve, but I don't think that's possible with styled components and Next.js. At the moment, the server has to rebuild the CSS whenever the page is rebuilt (#3380), so whenever content changes. However, the CSS only changes once a week, when we deploy. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 this stylesheet fixes the page styling issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Breakpoints should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is odd. I built the app a second time. After the second build, I don't see the server-side stylesheet in the HTML, so it's unstyled again when it first loads. Screen.Recording.2023-10-02.at.12.59.12.movThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems ok after running the bootstrap script and building for a third time. 🤷♂️ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good to know, thanks for double checking! |
||
|
||
import { useServerInsertedHTML } from 'next/navigation' | ||
import { ServerStyleSheet, StyleSheetManager } from 'styled-components' | ||
import { useState } from 'react' | ||
|
||
export default function StyledComponentsRegistry({ | ||
children | ||
}) { | ||
// Only create stylesheet once with lazy initial state | ||
// x-ref: https://reactjs.org/docs/hooks-reference.html#lazy-initial-state | ||
const [styledComponentsStyleSheet] = useState(() => new ServerStyleSheet()) | ||
|
||
useServerInsertedHTML(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This hook name is confusing in a client-side component. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although this is a client component, you noted earlier the downloaded HTML includes an inline stylesheet. Client components still run once on the server, and then again in the browser. This code is copied from the styled-components example: https://nextjs.org/docs/app/building-your-application/styling/css-in-js#styled-components Do you recommend changing the function name? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The hook's name is set by Next.js, so that's fine. I was just confused as to how this component works. |
||
const styles = styledComponentsStyleSheet.getStyleElement() | ||
styledComponentsStyleSheet.instance.clearTag() | ||
return <>{styles}</> | ||
}) | ||
|
||
if (typeof window !== 'undefined') return <>{children}</> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This checks if the code is running in a browser, but the file specifies There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm also a bit confused. I used the example from https://nextjs.org/docs/app/building-your-application/styling/css-in-js#styled-components, but don't totally understand why this line is included. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good to know I'm not the only one that's confused by how this works. 😄 |
||
|
||
return ( | ||
<StyleSheetManager sheet={styledComponentsStyleSheet.instance}> | ||
goplayoutside3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{children} | ||
</StyleSheetManager> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function UserPage() { | ||
return ( | ||
<div> | ||
<p>This is lib-user</p> | ||
</div> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use client' | ||
|
||
import { Grommet } from 'grommet' | ||
import zooTheme from '@zooniverse/grommet-theme' | ||
import { base as baseTheme } from 'grommet' | ||
import { ZooHeader, ZooFooter } from '@zooniverse/react-components' | ||
|
||
const theme = { ...baseTheme, ...zooTheme } | ||
|
||
export default function RootLayout({ children }) { | ||
return ( | ||
<Grommet | ||
background={{ | ||
dark: 'dark-1', | ||
light: 'light-1' | ||
}} | ||
theme={theme} | ||
> | ||
<ZooHeader /> | ||
<main>{children}</main> | ||
goplayoutside3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<ZooFooter /> | ||
</Grommet> | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there a
.gitignore
file?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are .gitignore files in app-project, app-content-pages, and lib-classifier. Should there not be one here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not sure. This one seems to be mostly duplicating the one at the root of the monorepo.