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

Replace NextJS with Vite #1431

Merged
merged 36 commits into from
Mar 13, 2024
Merged

Replace NextJS with Vite #1431

merged 36 commits into from
Mar 13, 2024

Conversation

Da-Colon
Copy link
Contributor

@Da-Colon Da-Colon commented Mar 11, 2024

  • remove next config and types
  • Add vite and react-router-dom
  • Add vite config
  • Create index.html (update with metadata from next/head)
  • Create main.tsx (entry point)
  • Add CSS imports, providers to entry point
  • Create router.tsx to handle page router
  • Add DAOController and Layout element to Router
  • Add Pages to Router (A few index -> default component name file changes)
  • Replace next's Script with custom hook
  • Replace next Link Component with React Router Link
  • Replace process.env -> import.meta with update ENV names
  • Replace next/image component with Chakra Image component
  • Replace next/router push instances with useNavigate
  • Replace package.json next scripts with vite runner

Testing

Note: Deployed preview will not work.

I deployed this branch manually on netlify. Here is the link: https://test-vite-fractalframework.netlify.app/

Da-Colon added 10 commits March 7, 2024 15:32
- remove next config and types
- Add vite and react-router-dom
- Add vite config
- Create index.html (update with metadata from next/head)
- Create main.tsx (entry point)
- Add CSS imports, providers to entry point
- Create router.tsx to handle page router
- Add DAOController and Layout element to Router
- Add Pages to Router (A few index -> default component name file changes)
- Replace next's Script with custom hook
- Replace next Link Component with React Router Link
- Replace process.env -> import.meta with update ENV names
- Replace next/image component with Chakra Image component
- Replace next/router push instances with `useNavigate`
- Replace package.json next scripts with vite runner
@Da-Colon Da-Colon self-assigned this Mar 11, 2024
@Da-Colon Da-Colon linked an issue Mar 11, 2024 that may be closed by this pull request
Copy link

netlify bot commented Mar 11, 2024

Deploy Preview for test-vite-fractalframework ready!

Name Link
🔨 Latest commit c152334
🔍 Latest deploy log https://app.netlify.com/sites/test-vite-fractalframework/deploys/65f1aff52e075b0008db3208
😎 Deploy Preview https://deploy-preview-1431--test-vite-fractalframework.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor Author

@Da-Colon Da-Colon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test everything workflow you can think of. Should only notice the app being smoother everywhere. report any weirdness and I'll look into it.

src/router.tsx Outdated
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was surprisingly pretty straight forward to create. Just takes the 'index' of each page folder formally the page.tsx and place as the element.

.env Outdated
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to update local env files as well from NEXT_PUBLIC_ -> VITE_APP_

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot test this since Goerli is no longer supported. Should we just remove?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah just remove this script - it was purely for user testing on Goerli, we don't need it anymore

vite.config.ts Outdated
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far in my testing, all I've had to update here is the plugin for nodepolyfils. This was fixing a 'process is not defined' and 'global is not defined' errors when setting up

@Da-Colon Da-Colon mentioned this pull request Mar 11, 2024
Copy link
Contributor

@mudrila mudrila left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing job!
Wasn't expecting it would be relatively simple. Have bunch of comments for changes, but other than that - looks good! Gonna test it in a moment

src/components/pages/DaoDashboard/Info/ParentLink.tsx Outdated Show resolved Hide resolved
src/components/ui/cards/DAOInfoCard.tsx Outdated Show resolved Hide resolved
@@ -6,13 +6,13 @@ import * as Sentry from '@sentry/react';
export function initErrorLogging() {
if (
process.env.NODE_ENV === 'development' ||
process.env.NEXT_PUBLIC_SENTRY_DSN_URL === undefined
import.meta.env.VITE_APP_SENTRY_DSN_URL === undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is not related to the topic of this PR, but we need to make sure it is not an empty string as well. We have VITE_APP_SENTRY_DSN_URL="" in .env and I think it is good idea to keep that on env file, but then we need to make sure it is not an empty string

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah just remove this script - it was purely for user testing on Goerli, we don't need it anymore

src/pages/DAOController.tsx Outdated Show resolved Hide resolved
src/pages/DAOController.tsx Outdated Show resolved Hide resolved
const { push } = useRouter();
const searchParams = useSearchParams();
const navigate = useNavigate();
let [searchParams] = useSearchParams();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be const I believe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but, please make it a const cause we're not changing it.

@Da-Colon
Copy link
Contributor Author

@mudrila All your comments have been address, sir. (+some)

Copy link
Member

@adamgall adamgall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the new VITE_APP_NAME env var in all the places in the codebase that we were originally using the APP_NAME constant defined in src/constants/common.ts? And then, remove that constant from common.ts?

src/vite-env.d.ts Outdated Show resolved Hide resolved
index.html Outdated Show resolved Hide resolved
index.html Outdated Show resolved Hide resolved
index.html Outdated Show resolved Hide resolved
src/pages/DAOController.tsx Outdated Show resolved Hide resolved
src/pages/DAOController.tsx Outdated Show resolved Hide resolved
src/providers/NetworkConfig/rainbow-kit.config.ts Outdated Show resolved Hide resolved
Copy link
Member

@adamgall adamgall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deployed site doesn't load if you refresh the page on any non-root URL.

This is known and expected.

There's a simple fix for Netlify hosting, which allows us to keep the BrowserRouter and not need to switch to a HashRouter.

See this commit from the fractal-interface-2 repo: decentdao/fractal-interface-2@6bc7702

/>
<meta
name="description"
content="Are you outgrowing your Multisig? Fractal extends Safe treasuries into on-chain hierarchies of permissions, token flows, and governance."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blah, I think that either this should be in an env var, or we just hardcode "Fractal" back into the places where we are using VITE_APP_NAME.

Why have some of this metadata hardcoded and others controlled by environment?

But whatever, it's fine for now.

export default defineConfig({
plugins: [nodePolyfills(), react()],
server: {
port: 3000,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Da-Colon just wondering, does it actually matter to force this to run on 3000? THIS AIN'T A NEXT APP ANY LONGER BOYYEEEEEE

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol fair. more for me and my history autocomplete :D

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really have a preference. btw we can definately just go with the defaults of vite.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My preference is that we just go with the vite default

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this whole file and associated other lizard-specific files get removed too? I'm not sure where we stand on that....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The export from this file isn't being consumed anywhere, so from a codebase perspective, it's safe to delete this file. I wonder if we should hold on to it for future use though...

const { push } = useRouter();
const searchParams = useSearchParams();
const navigate = useNavigate();
let [searchParams] = useSearchParams();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but, please make it a const cause we're not changing it.

@adamgall adamgall self-requested a review March 12, 2024 20:22
@adamgall
Copy link
Member

@Da-Colon can you explain the difference between chakra's <Link> component and react-router-dom's <Link> component? There seems to be extensive use of both in the codebase, and I'm not sure what the distinction is between them.

This commit has me scratching my head... why change the href to to on these chakra <Link>'s and not others?

@Da-Colon
Copy link
Contributor Author

@Da-Colon can you explain the difference between chakra's <Link> component and react-router-dom's <Link> component? There seems to be extensive use of both in the codebase, and I'm not sure what the distinction is between them.

This commit has me scratching my head... why change the href to to on these chakra <Link>'s and not others?

@adamgall

Chakra-UI's Link basically is a stylable <a> element
React-Router's Link adds React Router's functionality to the <a> element. https://reactrouter.com/en/main/components/link

image

Switching to to property for these allowed it to pick up that we are just navigating to a different page rather than reloading the document


As far as the various uses. Looking through how I've updated it.

React-Router's Link is used when the navigation is internal

Chakra-UI's Link is used when navigation is external or needs to be styled.

In the case of needing to be styled and internal. Chakra's as property is used. This allows Chakra's styling ability to be used along side React-Router's properties (why you saw these switch to to property as well)

@adamgall
Copy link
Member

@Da-Colon this makes a lot of sense, thank you

@Da-Colon Da-Colon changed the base branch from lesgoo/switchtovite to develop March 13, 2024 14:18
@adamgall adamgall merged commit 0cddf55 into develop Mar 13, 2024
7 checks passed
@adamgall adamgall deleted the lesgoo/switchtovite-removeNextJS branch March 13, 2024 16:40
@tomstuart123
Copy link

So I think this is good to go

Successful Test cases for both multisig + token dao

  • Create a DAO
  • delegate (token only)
  • vote / sign
  • wait for timelock
  • execute

these were for subdao, token send and create a proposal flow

just a note - I did have old issues reccur with subdao activity but david pointed me to a seperate PR for that - https://discord.com/channels/839548879216181309/1174434485043998860/1219698481091055699

final note - I did get this error that I had never seen before. Hard to replicate
Screenshot 2024-03-19 at 17 50 29

this was the only new thing and happened pretty rarely. I think we're good to go on this

@Da-Colon
Copy link
Contributor Author

New Error you are experiencing is this?

https://github.com/orgs/decentdao/projects/32/views/3?pane=issue&itemId=56621736

@adamgall adamgall mentioned this pull request Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Static Upgrade
4 participants