Skip to content
This repository was archived by the owner on Feb 15, 2022. It is now read-only.

Auto-generate pages directory #140

Closed
agarwal opened this issue Mar 11, 2021 · 11 comments
Closed

Auto-generate pages directory #140

agarwal opened this issue Mar 11, 2021 · 11 comments

Comments

@agarwal
Copy link
Member

agarwal commented Mar 11, 2021

We have to implement our pages in a directory called res_pages/ due to ReScript naming conflicts with having multiple files named Index.res, but eventually NextJS requires a pages/ directory. Currently we manually write a file in pages/ with some boilerplate, which points to the corresponding file in res_pages/. It should be possible to fully auto-generate the pages/ directory.

@ghost
Copy link

ghost commented Apr 3, 2021

resource tutorials.js - this is a special case that will need slightly more thought when approaching this issue.

@ghost ghost mentioned this issue Apr 3, 2021
@ghost
Copy link

ghost commented Apr 3, 2021

The following is an issue tracking the upstream changes needed in the ReScript compiler to obviate needing to generate this boilerplate: rescript-lang/rescript#4874

@ghost
Copy link

ghost commented Apr 5, 2021

getStaticProps should be required and this tool should raise an error if it's missing. A page component without getStaticProps is only useful during initial drafts and even then, creating a skeleton getStaticProps will enforce good discipline.

@ghost
Copy link

ghost commented Apr 5, 2021

Similarly, for pages that use a pattern like [slug].js, both getStaticProps and getStaticPaths should be required and this tool should raise an error if either one is missing.

@ghost
Copy link

ghost commented Apr 9, 2021

The implementation of this task may introduce a wrapper around next dev and next build, so that it can always perform actions before the build

@agarwal
Copy link
Member Author

agarwal commented Apr 9, 2021

getStaticProps should be required and this tool should raise an error if it's missing.
Similarly, for pages that use a pattern like [slug].js, both getStaticProps and getStaticPaths should be required

We can get this by using a module signature, though we might then want a linter to assure that all pages do constrain themselves to the right signature.

@ghost
Copy link

ghost commented May 1, 2021

I may have come up with a suitable workaround for this issue. I propose we forgo this task if Ashish accepts my workaround approach. Here is the essence of the approach:

  • Do not use javascript wrappers around ReScript page components.
  • For pages that have no duplicate clash, no additional work is needed.
  • For pages that have a name clash such as subdir1/somepage.res and subdir2/somepage.res, each of the pages can use the dynamic path matching feature of NextJS. The page components can use any name, as long as they are distinct, such as [somepage1].res and [somepage2].res, and then we can match these page components with a specific path by implementing a specific getStaticPaths to return a collection with a single path, somepage, in each dynamic page component. (Note: For index pages, we need to use catch all matches using [[...index1]].js and [[...index2]].js.)

@ghost
Copy link

ghost commented May 1, 2021

I am closing this issue for now. Please reopen if the approach noted above is not acceptable.

@ghost ghost closed this as completed May 1, 2021
@ghost
Copy link

ghost commented Jun 10, 2021

I may have declared victory too early. I tried using [[...index]].res and seemed to encounter an illegal filename. I will try to use RootIndex.res with a symlink from /pages/[[...index]].js to RootIndex.js and report back if that works. If it doesn't work, I may have to reopen this issue and revert #315.

@ghost ghost reopened this Jun 10, 2021
@agarwal
Copy link
Member Author

agarwal commented Jun 16, 2021

I may have to reopen this issue and revert #315

That would be sad!

@ghost
Copy link

ghost commented Jun 24, 2021

I thought about this more. The way that the url's currently work probably only results in one page called Index.res. For any subpaths like /news, then you only need /news.res. You wouldn't need news/index.res, which is how I had envisioned clashes between [[..index]].res modules to occur.

@ghost ghost closed this as completed Jun 24, 2021
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant