-
-
Notifications
You must be signed in to change notification settings - Fork 253
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
feat: Next.js 13 RSC integration #139
Closed
Closed
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Use Next.js internal request storage
- Loading branch information
commit 3ad8b5930250986ce5205a0c8344dbeda921700a
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
.DS_Store | ||
node_modules | ||
dist | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {requestAsyncStorage} from 'next/dist/client/components/request-async-storage'; | ||
|
||
const key = '__next-intl'; | ||
|
||
/** | ||
* Returns the request-level storage of Nex.js where typically headers | ||
* and cookies are stored. This is recreated for every request. | ||
*/ | ||
function getStorage() { | ||
const requestStore = | ||
requestAsyncStorage && 'getStore' in requestAsyncStorage | ||
? requestAsyncStorage.getStore()! | ||
: requestAsyncStorage; | ||
|
||
return requestStore; | ||
} | ||
|
||
export default { | ||
set(value: any) { | ||
const storage = getStorage(); | ||
(storage as any)[key] = value; | ||
}, | ||
get() { | ||
const storage = getStorage(); | ||
return (storage as any)[key]; | ||
} | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe wrap all pages under optional
[[locale]]
then get usingparams
https://beta.nextjs.org/docs/routing/defining-routes#example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey and thank you for your interest! Yep, that seems to work, I've experimented with it here:
next-intl/packages/example/src/app/[locale]/page.tsx
Lines 11 to 15 in ccb9c8a
I think that part is doable, the part where I currently don't see an ergonomic solution is how global configuration like messages can be passed to the library (see the topic about context in the PR description).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried some workarounds,
1, Using singleton — Failed because for RSC, initializing on root layout requires 2 render to assign the
messages
object.2. Using third-party state manager like zustand — Failed because of the same reason as number 1.
Probably the solution is gonna be around client component. To use in a server component we could provide utility component like
<T key='dashboard.hi' />
. Performance-wise, next will also server-render client components so the downside is on developer experience. But won't be much I think.