Need support referring same singleton between different page's getStaticProps
during building time.
#72005
Labels
bug
Issue was opened via the bug report template.
Module Resolution
Module resolution (CJS / ESM, module resolving)
Link to the code that reproduces this issue
https://github.com/PrinOrange/need-support-singleton-for-different-page.git
To Reproduce
getStaticProps
.In PageA,
And in PageB
And so on, refer this singleton in different pages
npm run build
to build the next.js projectStart initializing my singleton
many timesThis means that in the SSG process of different pages, each page will initialize its own
MySingleton
, and not use the sameMySingleton
.This will lead to a problem: if initializing
MySingleton
is a very time-consuming process, each page will generate its ownMySingleton
, and this unnecessary multiple initialization will seriously slow down the build performance.In addition, and more seriously: if initializing the Singleton is not an idempotent operation (such as connecting to a database), then this will cause errors to occur.
Current vs. Expected behavior
My purpose is set a singleton in a module, and every page's
getStaticProps
should use same one singleton during building time. It means that the module singleton is supposed to be initialized once. Because the singleton initializing is very time-costing.Provide environment information
Which area(s) are affected? (Select all that apply)
Module Resolution
Which stage(s) are affected? (Select all that apply)
next build (local)
Additional context
No response
The text was updated successfully, but these errors were encountered: