-
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
Conversation
packages/app-root/.gitignore
Outdated
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.
Okay I think I solved the FOUC! I ended up creating a test project outside of the monorepo workspace that included the same dependencies and file structure here. During that process, I finally saw a warning that Grommet is incompatible with styled-components v6, so I bumped the version back to v5. @eatyourgreens when you have a minute, could you take a look at this branch locally, try I plan to add an ADR to this PR before marking it ready for review, and will elaborate on next steps needed for app-root in #5429. |
@@ -0,0 +1,27 @@ | |||
'use client' |
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.
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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Breakpoints should be 48rem
, not 768px
, but that's probably a bug in the Grommet theme.
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.
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.mov
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know, thanks for double checking!
return <>{styles}</> | ||
}) | ||
|
||
if (typeof window !== 'undefined') return <>{children}</> |
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.
This checks if the code is running in a browser, but the file specifies use client
, so that's confusing.
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 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 comment
The 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. 😄
// 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 comment
The 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 comment
The 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 comment
The 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.
I'm running this locally, and the links in |
The local app uses HTTP. At some point we'll also need to add a custom dev server to handle HTTPS, so that we can authenticate to Panoptes in development. EDIT: we'll need a Dockerfile too, so that we can build and deploy. Nothing urgent, but making sure that we've got these on our radar so that we don't miss them out. |
I've published import ZooHeader from '@zooniverse/react-components/ZooHeader'
import ZooFooter from '@zooniverse/react-components/ZooFooter' In Next.js 13.5, you can also try optimising package imports in |
Re these points:
I've added them to the running list in #5429 which might be converted to a project board 👍 |
Co-authored-by: Jim O'Donnell <jim@zooniverse.org>
Changes here look good if the aim of this PR is to get the basic theme styles working. 👍 |
Cool! I'm going to add documentation to the Readme and an ADR. I'll change this to ready for final review in the next 24 hrs. |
Sorry, one other comment. Have you any thoughts on how this app will use the staging vs. production Panoptes API? At the moment, production projects are served from front-end-monorepo/packages/app-project/middleware.js Lines 57 to 62 in 61804c0
Obviously, with this app, we'll have staging/production users too. Also a staging API homepage and a production API homepage. On the homepage, I think that Featured Projects is the only place where the Panoptes API would be used on the server. All the other Panoptes requests are made by the browser (I think.) |
packages/app-root/jsconfig.json
Outdated
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.
What does this file do?
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.
Oh, is it a Visual Studio thing?
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.
Correct! I'll delete this 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.
Uh oh, this file is actually responsible for resolving paths. When I delete it there's an error:
Module not found: Can't resolve '@/components/RootLayout'
> 1 | import RootLayout from '@/components/RootLayout'
I've got a lot of questions, but I don't think there's anything that would stop this from merging. What do you think? |
The weird thing is, there's nothing in the pages that uses JS. If you disable JS in your browser, then load http://localhost:3000, the new home page loads just fine, with CSS styles inlined into the page head. |
I downgraded #5411 to Next 13.5.3 and it still won't build the content pages storybook, so the problem might be the latest update to Storybook (7.4.6.) |
I'm going to split #5411 into one PR that fixes the build warnings for Next 13.4, and a second PR that upgrades to Next 13.5. |
I ran @eatyourgreens in your network screenshot, what is the significance of "transferred" versus "size"? |
Oh wait, I just answered my own question. Even though |
I think Next.js gzips by default, in which case that's showing gzipped size vs. actual size. |
Ah actually, it may just be a naming difference. In the bottom bar, Chrome "resources" is the actual size and "transferred" is the gzipped. Whereas in Firefox, "Size" is actual size and it's displayed directly next to total "transferred". |
So, just for my understanding - We're concerned about actual size of ~600kb versus gzipped ~200kb because the browser still has to uncompress the gzipped content to the size of 600kb and send it to the user? |
The browser downloads ~170kB, then unzips the received file, then runs it. So it's running 600kB of JS, which is why Lighthouse has a poor performance score. There's also a performance hit because unzipping takes time too. |
We should turn off gzip in production, because our problems with the CDN in the past were caused by FrontDoor trying to gzip resources that were already gzipped. |
Nice to see that imports from |
I wonder why EDIT: |
Agreed it's frustrating react is bundled twice! As for i18next, the whole library is imported in I'm not going to address either of those issues in this PR, but will definitely bring it up during next week's standup and/or document it 👍 |
We could alias |
Package
app-root
Linked Issue and/or Talk Post
FEM packages structure discussion: #5089
Toward: #5429
Describe your changes
How to Review
app-root can be run locally with
yarn dev
Please read through ADR 54 to check for relevant information and typos.