scaffold-eth / scaffold-eth-2

Open source forkable Ethereum dev stack
https://scaffoldeth.io
MIT License
1.19k stars 745 forks source link

add generateStaticParams to blockexplorer address and txHash #825

Closed technophile-04 closed 3 months ago

technophile-04 commented 3 months ago

Description

An alternate solution to #824 (which doesn't require manual work)

As the error mentioned in #785 :

Error: Page "/blockexplorer/transaction/[txHash]" is missing "generateStaticParams()" so it cannot be used with "output: export" config.

Therefore used generateStaticParams from NextJs.

export function generateStaticParams() {
  return [{ address: "0x0000000000000000000000000000000000000000" }];
}

having the above code in blockexplorers /[address] & /[txHash], when NextJs build the prod version it will generate 2 static dummy pages and won't fail.


Does having generateStaticParams break the blockexplorer when tinkering around on localnetwork ?

No, since dynamicPramas are enabled by default it should generate that page on demand.

So TLDR; nothing breaks (at least In my testing) there is no side effect to current version of SE-2 and also having output:export in next.config.ts works out of the box.

The downside of the above thing, lol we have to add very hacky code in our codebase.


### Side quest : Also an difference which I noticed on vercel deployment: | Main | This Branch | | ----- | ------------ | | ![Screenshot 2024-04-23 at 11 59 53 PM](https://github.com/scaffold-eth/scaffold-eth-2/assets/80153681/a49d3c42-093e-4b37-9ec8-0c65dc4453ef) | ![Screenshot 2024-04-24 at 12 01 01 AM](https://github.com/scaffold-eth/scaffold-eth-2/assets/80153681/0dcd362e-6d3b-42e5-bce2-76b92347a5e8) | Notice how on `main` branch is explicitly mentioned it spun up serverless functions for handling `/blockexplorer` page but didn't mention about it on this branch deployment. Since `dynamicParams` are enabled are by default it ideally should have shown right ? If I go to logs of request I made, it shows their that its using serverless functions :
Demo image: ![Screenshot 2024-04-24 at 12 01 33 AM](https://github.com/scaffold-eth/scaffold-eth-2/assets/80153681/515341f8-3eba-425d-8978-d91f2d539f10)
technophile-04 commented 3 months ago

Just asking for a review to know what you guys think 🙌, also we can completely close this if it feels too hacky !

Need to update component name, and maybe having other default txHash instead of using address as txHash? Will update it later

rin-st commented 3 months ago

btw we have next:build script in package.json but don't have next:serve. Probably it's worth to add it

rin-st commented 3 months ago

Side quest : Notice how on main branch is explicitly mentioned it spun up serverless functions for handling /blockexplorer page but didn't mention about it on this branch deployment. Since dynamicParams are enabled are by default it ideally should have shown right ?

As I understand it's moved to ISR block

image
technophile-04 commented 3 months ago

btw we have next:build script in package.json but don't have next:serve. Probably it's worth to add it

Yup, makes sense! updated it, Thanks Rinat !

rin-st commented 3 months ago

Thanks @technophile-04 , gj! Yes, looking a bit hacky but a much better solution than https://github.com/scaffold-eth/scaffold-eth-2/pull/824

technophile-04 commented 3 months ago

Merging this! Thanks all for reviews and suggestion !