Skip to content

Allow special characters in path and filenames #4624

Closed

Description

@Kingdutch

Background

Next.js is the defacto solution for creating dynamic React.js websites. It allows to easily create applications and fine-tune where rendering happens (client or server). ReScript would be a great match here to provide typesafety in these solutions. Some great work has been done by https://github.com/mrmurphy/reason-nextjs already but a large painpoint remains.

Next.js uses special characters such as [id] and [...slug] in the pathnames and filenames of files in the pages/ directory. These are variable placeholders that are used for route arguments. Documentation for this can be found here: https://nextjs.org/docs/routing/dynamic-routes

Requested change

By allowing special characters (specifically those used by Next.js routing) in path and filenames, integration with the Next.js framework would be greatly simplified. This could be put behind configuration that limits it to a specific folder that may not be used as module imports (to work around the module naming limitation).

Activity

  1. bobzhang commented on Aug 14, 2020

    @bobzhang
    Member

    note we currently support something like this

    [@@@bs.config { no_export} ]

    if we add a payload in no_export to change filename, would that be enough?

    [@@@bs.config { no_export = "123"} ]

    It will generate "123.js"

  2. Kingdutch commented on Aug 14, 2020

    @Kingdutch
    ContributorAuthor

    Ooh interesting! Does this prevent Reason exports only? There are exports required in the JavaScript code for the page components

  3. bobzhang commented on Sep 10, 2020

    @bobzhang
    Member

    hi @Kingdutch we will relax the name a little bit to allow, 404.ml.
    We need some more input that which names are desired to be allowed
    Note that you still can not access it due to syntax restriction.

  4. added a commit that references this issue on Sep 10, 2020
  5. bobzhang commented on Sep 10, 2020

    @bobzhang
    Member

    see #4685

  6. added a commit that references this issue on Sep 10, 2020
  7. Kingdutch commented on Sep 10, 2020

    @Kingdutch
    ContributorAuthor

    Thanks @bobzhang I think allowing numbers is a cool first step. It mostly helps with error pages (404, 500, etc.) :D

    The game-changer here would still be adding support for [, ], and . though so that URL arguments can be specified :D

    Not being able to access these modules is fine as you're not supposed to access Next.js or Page components from other files anyway.

  8. bobzhang commented on Sep 10, 2020

    @bobzhang
    Member

    #1436 we could also support Button.Android.res
    Where could I find file names using [,]?

  9. Kingdutch commented on Sep 10, 2020

    @Kingdutch
    ContributorAuthor

    @bobzhang you can see in the Next.js Dynamic Routes documentation how they use [, ], and . in the filename and then map this to arguments in the URL and query parameters in the component.

    The current Next.js bindings recommend using symlinks to get the correct filename. However, this is not a great experience when working with git or deploying to platforms where it's uncertain if symlinks are available. So allowing the caracters []. in a ReScript filename would mean we can work without symlinks and use the BuckleScript output directly.

  10. bobzhang commented on Sep 12, 2020

    @bobzhang
    Member
  11. supriyo commented on Sep 14, 2020

    @supriyo

    @bobzhang Here is a list of file name examples to support that would make working with nextjs easier:

    404.res
    _app.res
    [slug_or_ID].res    
    [...params].res 
    [...params_max_3].res
    [[...params]].res 
    
  12. bobzhang commented on Sep 15, 2020

    @bobzhang
    Member

    @supriyo can you check if #4690 covers all your cases
    Note this is experimental, we may apply restrictions back if there are some conflicts we don't recognize yet

  13. Kingdutch commented on Sep 15, 2020

    @Kingdutch
    ContributorAuthor

    @bobzhang From reading the PR it looks good to me. I don't have a ReScript Next.js repository nearby to test the individual files unfortunately. I could do so later this week.

  14. supriyo commented on Sep 15, 2020

    @supriyo

    @bobzhang That looks good to me too. This is will be really helpful. Thanks!

  15. bobzhang commented on Sep 17, 2020

    @bobzhang
    Member

    experimental support landed in master

  16. JanDez commented on Jun 24, 2021

    @JanDez

    I'm at Spanish speaker, so many of the thing that I make are in Spanish. I was working on at product list and thoses routes that include "´" and "ñ" like navegación, niños, técnico and like so, don't get to be render. How can i aproach to this in future projects?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions