File tree Expand file tree Collapse file tree
packages/react/src/server Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ 'use server' ;
2+
3+ import { ReplexicaChunkGetterArgs , ReplexicaChunkProps } from "../types" ;
4+ import { cookies } from 'next/headers' ;
5+
6+ export type ReplexicaServerChunkProps = ReplexicaChunkProps & {
7+ strategy ?: 'cookie' ;
8+ importer : ( locale : string ) => ReplexicaChunkGetterArgs [ 'data' ] ;
9+ } ;
10+
11+ export async function ReplexicaServerChunk ( props : ReplexicaServerChunkProps ) {
12+ const locale = await getCurrentLocale ( ) ;
13+ console . log ( `[ReplexicaServerChunk] locale: ${ locale } ` ) ;
14+ const data = await props . importer ( locale ) ;
15+ console . log ( `[ReplexicaServerChunk] data: ${ JSON . stringify ( data ) } ` ) ;
16+ const result = await getReplexicaChunkContent ( {
17+ data : data ,
18+ selector : {
19+ fileId : props . fileId ,
20+ scopeId : props . scopeId ,
21+ chunkId : props . chunkId ,
22+ } ,
23+ } ) ;
24+
25+ return result ;
26+ }
27+
28+ export async function getReplexicaChunkContent ( args : ReplexicaChunkGetterArgs ) {
29+ const { fileId, scopeId, chunkId } = args . selector ;
30+ const text = args . data ?. [ fileId ] ?. [ scopeId ] ?. [ chunkId ] ;
31+ const fallback = `chunk1#${ fileId } :${ scopeId } .${ chunkId } ` ;
32+ return text || fallback ;
33+ }
34+
35+ export async function getCurrentLocale ( ) {
36+ const cookieMgr = cookies ( ) ;
37+ return cookieMgr . get ( 'locale' ) ?. value || 'en' ;
38+ }
Original file line number Diff line number Diff line change 1+ export * from './chunk' ;
2+ export * from './proxy' ;
Original file line number Diff line number Diff line change 1+ 'use server' ;
2+
3+ import { createElement } from "react" ;
4+ import { ReplexicaProxyProps , ReplexicaChunkSelector } from "../types" ;
5+ import { getReplexicaChunkContent } from './chunk' ;
6+
7+ export async function ReplexicaServerProxy < P extends { } > ( props : ReplexicaProxyProps < P > ) {
8+ // const data = {};
9+
10+ // let propsPatch: Partial<P> = {};
11+
12+ // for (const [key, value] of Object.entries(props.attributes || {})) {
13+ // const result = await getReplexicaChunkContent({
14+ // data,
15+ // selector: value as ReplexicaChunkSelector,
16+ // });
17+
18+ // propsPatch = {
19+ // ...propsPatch,
20+ // [key]: result,
21+ // };
22+ // }
23+
24+ // const modifiedProps: P = {
25+ // ...props.targetProps,
26+ // ...propsPatch,
27+ // };
28+
29+ // return createElement(
30+ // props.target,
31+ // modifiedProps,
32+ // );
33+
34+ return null ;
35+ }
You can’t perform that action at this time.
0 commit comments