-
Notifications
You must be signed in to change notification settings - Fork 48
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
Migrate to nextjs app router #695
Conversation
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 point of using app router is to enable server-side rendering right? Do users need to be aware of which routes and components use SSR and avoid o1js in them?
'--import-alias "@/*"', | ||
'--no-app', | ||
'--app', |
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.
Should we add this change to the changelog?
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.
+1
|
||
export default function Home() { | ||
useEffect(() => { | ||
(async () => { | ||
const { Mina, PublicKey } = await import('o1js'); | ||
const { Add } = await import('../../../contracts/build/src/'); | ||
const { Add } = await import('../../contracts/build/src/'); | ||
|
||
// Update this to use the address (public key) for your zkApp account. | ||
// To try it out, you can try this address for an example "Add" smart contract that we've deployed to |
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.
Did you test if uncommenting this code works with your changes?
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 code doesn't error, but it's also not really doing anything. Looking at this more closely it seems like that zkapp address might be out of date. Maybe we should either remove the example code or update it to really interact with the network. What do you think?
const { Mina, PublicKey,fetchAccount } = await import('o1js');
const { Add } = await import('../../contracts/build/src/');
// connect Mina to testnet
const Network = Mina.Network(
'https://api.minascan.io/node/devnet/v1/graphql'
);
Mina.setActiveInstance(Network);
// address of deployed Add contract on testnet https://minascan.io/devnet/account/B62qnTDEeYtBHBePA4yhCt4TCgDtA4L2CGvK7PirbJyX4pKH8bmtWe5
const zkAppAddress = `B62qnTDEeYtBHBePA4yhCt4TCgDtA4L2CGvK7PirbJyX4pKH8bmtWe5`;
await fetchAccount({publicKey: zkAppAddress});
const zkApp = new Add(PublicKey.fromBase58(zkAppAddress));
console.log("Current num: ", zkApp.num.get().toString());
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.
Yeah, sounds like a different PR though 👍
We can reconsider what the right format is for demoing o1js in a boilerplate app.
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 contract is currently deployed on devnet. https://minascan.io/devnet/account/B62qnTDEeYtBHBePA4yhCt4TCgDtA4L2CGvK7PirbJyX4pKH8bmtWe5?type=zk-acc
This example code was originally added to demonstrate how to import a contract into a UI. The goal was to eventually add further interactions in this example boilerplate.
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.
B62qnTDEeYtBHBePA4yhCt4TCgDtA4L2CGvK7PirbJyX4pKH8bmtWe5
is the one that I deployed during testing, I will replace the old address with this one in all of the cli files!
One of the reasons Next moved to app router was to better support React's server components. Info explaining usage with server components may be well suited to a Next.js specific section in the docs where we also call out things like loading the SDK in |
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.
Nice work! I cloned your repo and was able to successfully generate a project using the app router. I'm approving in advance, but could you change the copy on the UI landing page to match the updated app router file path?
zkapp-cli/src/lib/ui/next/customNextPage.js
Lines 60 to 61 in 512e7ed
Get started by editing | |
<code className={styles.code}> src/pages/index.js</code> or <code className={styles.code}> src/pages/index.tsx</code> |
'--import-alias "@/*"', | ||
'--no-app', | ||
'--app', |
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.
+1
|
||
export default function Home() { | ||
useEffect(() => { | ||
(async () => { | ||
const { Mina, PublicKey } = await import('o1js'); | ||
const { Add } = await import('../../../contracts/build/src/'); | ||
const { Add } = await import('../../contracts/build/src/'); | ||
|
||
// Update this to use the address (public key) for your zkApp account. | ||
// To try it out, you can try this address for an example "Add" smart contract that we've deployed to |
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 contract is currently deployed on devnet. https://minascan.io/devnet/account/B62qnTDEeYtBHBePA4yhCt4TCgDtA4L2CGvK7PirbJyX4pKH8bmtWe5?type=zk-acc
This example code was originally added to demonstrate how to import a contract into a UI. The goal was to eventually add further interactions in this example boilerplate.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #695 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 11 11
Lines 1491 1475 -16
Branches 312 300 -12
=========================================
- Hits 1491 1475 -16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Vercel is also pushing the app router as the new standard for NextJS. A user can chose only to use client side components with the app router if they want. |
fs.writeFileSync(path.join('ui', 'next.config.mjs'), newNextConfig); | ||
|
||
const indexFileName = useTypescript ? 'index.tsx' : 'index.js'; | ||
const pageFileName = 'page.tsx'; | ||
|
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.
It looks like there are some legacy create-next-app
boilerplate styles and fonts leftover in the app
folder when a project is generated. I think it is a good idea to remove these so they do not conflict with the other assets. You could empty the app
directory with something like fs.emptyDirSync
or similar before adding the customNextPage and any other files to the directory.
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 catch, cleared out the whole directory
src/lib/project.js
Outdated
); | ||
|
||
// Removes create-next-app assets | ||
fs.emptyDirSync(path.join('ui', 'public')); | ||
if (fs.existsSync(path.join('ui', 'app', 'favicon.ico'))) { |
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.
Similar comment to above.
It looks like there are some legacy create-next-app
boilerplate styles and fonts leftover in the app folder when a project is generated. You could empty the entire app
directory instead of just removing the favicon here with something like fs.emptyDirSync
or similar before adding the customNextPage and any other files to the directory.
'utf8' | ||
); | ||
|
||
appFile = appFile.replace( | ||
pageFile = pageFile.replace( | ||
'export default function', | ||
`import './reactCOIServiceWorker'; | ||
|
||
export default function` |
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.
@essential-breads were you able to test if the deploy to GitHub Pages flow works correctly with the appRouter changes? It might be out of scope for this PR, but I will add an issue so we don't forget to verify that everything works.
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.
Yep GH pages is fully tested!
Updates the project starter to use the latest version of Nextjs with app router and no
src
directory. Removes the js project option. Closes#583
#400