mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2026-02-07 00:24:06 +00:00
Using a 'web server aware' Node library, with JavaScriptServices / NodeServices (React SPA) #515
Closed
opened 2025-08-09 17:16:35 +00:00 by fergalmoran
·
0 comments
No Branch/Tag Specified
master
rybrande/masterToSrc
pakrym/no-console-fb
release/2.2
pakrym/remove-obsole-api-usage
maestro/release/2.2
maestro/master
release/2.1
release/2.0
rybrande/MergeRelease21IntoDev
rel/2.0.0-extensions
angular-animations-example
fix-angular-material-publishing
rel/2.0.0-templates
httpwithstatetransfer-example
rel/2.0.0-preview2-templates
aspnet-webpack-react-2.x
angular4-prerender-data-example
version-1.x
angular2-lazy-loading-example
581-isomorphic-react-cookies-example
example-using-typescript-paths-for-494
v1.0.x
angular2-materialize-example
redux-typed-1-x
primeng-example
font-awesome-example
karma-testing-example
2.2.0
2.2.0-preview3
2.2.0-preview2
2.2.0-preview1
2.1.1
2.1.0
2.0.4
2.1.0-rc1-final
2.1.0-preview2-final
2.0.3
2.1.0-preview1-final
2.0.2
2.0.1
rel/2.0.0
rel/2.0.0-preview2
Labels
Clear labels
2 - Working
2 - Working
3 - Done
3 - Done
3 - Done
3 - Done
3 - Done
3 - Done
3 - Done
angular
angular
angular
angular
angular
bug
bug
bug
bug
bug
bug
bug
bug
bug
core
core
core
core
core
core
core
duplicate
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
enhancement
external
external
P1
P1
P1
P1
P1
P1
P2
P2
P2
P2
P2
P2
P2
P2
P2
PRI: 1 - Required
react
react
task
task
up-for-grabs
up-for-grabs
up-for-grabs
waiting
waiting
waiting
waiting
No Label
Milestone
No items
No Milestone
Projects
Clear projects
No project
Assignees
fergalmoran
Clear assignees
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: github/JavaScriptServices#515
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @mcquiggd on 8/11/2017
(Although this topic specifically mentions i18next, this could equally apply to other node packages that typically expect to have access to a Node web server such as Express, and some guidance would be most helpful.)
Scenario:
I wish to integrate the Node internationalization library
i18nextto provide language detection (initially browser accept-language headers in the request, or url segment such as /en-GB/), client side language selection (drop down), client side persistence of selected language (cookie / local storage / Redux), caching of translation data (local storage / Redux), translation of text client side and most importantly in the pre-rendered server side environment.Usual approach:
The normal way to do this with a fully isomorphic JavaScript app would be to use a plugin package (in this case
i18next-express-middleware), that has access to the server-side request and response, to perform language detection by accessing the request context - example server.js here.JavaScriptServices / NodeServices approach:
The actual loading of locales, and translation of text within my React components, can be achieved as normal once the i18next instance is initialised (tested this by specifying a default language).
The owner of the i18next project described the process of language detection and instance initialization as follows:
However, it seems to me that NodeServices execution context has no knowledge of the web environment itself, other than the data that is passed to it via the
asp-prerender-datatag helper.So, it also seems to me that any examination of the web request has to be performed in the .Net Core pipeline, with relevant parameters determined.
This would then be passed from the controller (e.g. Home/Index) to the corresponding view that contains
asp-prerender-moduletag and useasp-prerender-datato pass along these parameters, which can then be accessed in theserver-boot.tsmodule. Here, I would use them to initialise the i18next instance, and allow its provider to supply locales to my components as normal, as they are rendered by NodeServices / WebPack.Then, I should pass data - the language detected via ASP.Net Core, the locale json data loaded from the server filesystem - back to the client via the globals return 'type', as is currently done with initial state for Redux. This would then be attached the data to the window object on the client side, and could be persisted into local storage to allow i18next to take over and work as normal from then on.
Questions:
Is my understanding of the Kestrel > AspNet Core > NodeServices flow, and that NodeServices is essentially a non-web aware Node context, correct?
The advice from the owner of i18next to 'clone the main instance of i18next, and change the language on that', is to ensure each request receives its own instance, with its own language detection result. I am presuming that this is only required due to Node / Express, and that in the JavaScriptServices / NodeServices framework, each request would have its own isolated Node context?
It's not clear to me exactly how NodeServices interacts with WebPack to return transpiled output to the browser, or how that pipeline is arranged. Is there an in-depth explanation somewhere of the full interaction of each component in a typical lifecycle?
Does the team have any guidance in terms of internationalization, in the current JavaScriptServices / NodeServices framework?
Many thanks for any feedback...