-
-
Notifications
You must be signed in to change notification settings - Fork 764
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
refactor: Use rewrites instead of custom server #689
Conversation
What could be really useful for me would be to have an example of updated README.md to know exactly how the setup changes and if there are any trade-offs :) |
@martpie Sure, I've updated the README now. However, I'm mostly hoping for actual code reviews, as I'm not sure if I've missed any edge cases, especially in the implementation having to do with Here's how the setup varies from the current
That's it. There shouldn't be any trade-offs, unless I've missed something! |
ba7baed
to
da55f08
Compare
It looks really great, I'll try to go through the changes. Is there any plan to support |
@martpie The main drawback at the moment is that As far as the other data fetching methods: at first glance it seems like And Keep in mind that |
Ah: something I'm not currently sure of, is if importing the middleware in |
da55f08
to
27f694f
Compare
Another thing to check is if this |
Importing the middleware in the app-with-translation hoc might cause the loading issue you described. With my experiment, which I did some time ago, I have integrated a custom middleware in _document, and the bundle sizes just exploded. Also, google speed insights tells that a large portion of the loading time gets spent interpreting code, but there is not much there. Removing the hoc entirely results in bundle sizes of a few dozen kb max, so I guess everything was pulled to the client. Another thing that made things for me very complicated to understand is the app-with-translation hoc and its internals. In the context of SSR, which is already quite challenging, things like hoisting, possible side effects with the other libraries included made things very complex to go forward. I have not looked at the project next-translate, but what they are proposing is that _app.js, _document.js, and _error.js are not going to be wrapped with the translations context, so it's not possible to translate these files directly. Maybe this is worth some exploring. |
@gurkerl83 Not sure if the NextJs tools are detailed enough to be trusted on this. Something like If the NextJs tools are to be trusted, here are the two outputs: With Custom Server (existing implementation)With Rewrites (new implementation)Feel free to give it a try yourself. It looks like there's no difference, however I'm hesitant to take that at face value. |
This comment has been minimized.
This comment has been minimized.
* refactor: Use rewrites instead of custom server (#689) * chore: Add .e2e to npmignore * v5.0.0-beta.0 * chore: Add scripts to npmignore * v5.0.0-beta.1 * 5.0.0-beta.2 * refactor: Require absolute localePath, and refactor out usage of eval * 5.0.0-beta.3 * refactor: Clean up example dir, remove class components * chore: Update core-js to v3 * docs: Update README * v5.0.0-beta.4 * Clean up release
How work custom routes with rewrites ? I'm working with diferent paths Like:
|
I solver with
In case someone is helpful |
@SantiagoMolinaOrozco What are |
@isaachinman sure, I'm going to share the full example: routes.js
next.config.js
somthing like that, i try to summarize my current configuration, improvement recommendations are received. |
This is a first start at refactoring out usage of a custom server.
This relies upon the incoming
rewrites
NextJs feature, which is still in an experimental phase. By combining therewrites
array with middleware inside_app
'sgetInitialProps
, we can achieve the same result as what previously required a custom server.Note that until NextJs supports middleware for normal routes (not just API routes), we'll need to take this
getInitialProps
middleware approach.For
rewrites
to work,localeSubpaths
need to be available both at build time (for NextJs to implementrewrites
), and at run time (fornext-i18next
to implement 302s, etc). To make this as easy as possible, I've droppedlocaleSubpaths
intopublicRuntimeConfig
in the example.The future of
next-i18next
will involve periodic and signficant rewrites as NextJs slowly releases the features which we need to actually support serverless targets in a first class way. Notable examples are normal-route-middlewares and plugin support. This work, however, is a good first start to these incremental refactors.Links
vercel/next.js#9081
vercel/next.js#9133
vercel/next.js#7208