@@ -21,54 +21,53 @@ export const resolveHead = (
2121 contentModules : ContentModule [ ] ,
2222 locale : string ,
2323 defaults ?: DocumentHeadValue
24- ) => {
25- const head = createDocumentHead ( defaults ) ;
26- const getData = ( ( loaderOrAction : LoaderInternal | ActionInternal ) => {
27- const id = loaderOrAction . __id ;
28- if ( loaderOrAction . __brand === 'server_loader' ) {
29- if ( ! ( id in endpoint . loaders ) ) {
30- throw new Error (
31- 'You can not get the returned data of a loader that has not been executed for this request.'
32- ) ;
24+ ) =>
25+ withLocale ( locale , ( ) => {
26+ const head = createDocumentHead ( defaults ) ;
27+ const getData = ( ( loaderOrAction : LoaderInternal | ActionInternal ) => {
28+ const id = loaderOrAction . __id ;
29+ if ( loaderOrAction . __brand === 'server_loader' ) {
30+ if ( ! ( id in endpoint . loaders ) ) {
31+ throw new Error (
32+ 'You can not get the returned data of a loader that has not been executed for this request.'
33+ ) ;
34+ }
3335 }
34- }
35- const data = endpoint . loaders [ id ] ;
36- if ( isPromise ( data ) ) {
37- throw new Error ( 'Loaders returning a promise can not be resolved for the head function.' ) ;
38- }
39- return data ;
40- } ) as any as ResolveSyncValue ;
36+ const data = endpoint . loaders [ id ] ;
37+ if ( isPromise ( data ) ) {
38+ throw new Error ( 'Loaders returning a promise can not be resolved for the head function.' ) ;
39+ }
40+ return data ;
41+ } ) as any as ResolveSyncValue ;
4142
42- const fns : Extract < ContentModuleHead , Function > [ ] = [ ] ;
43- for ( const contentModule of contentModules ) {
44- const contentModuleHead = contentModule ?. head ;
45- if ( contentModuleHead ) {
46- if ( typeof contentModuleHead === 'function' ) {
47- // Functions are executed inner before outer
48- fns . unshift ( contentModuleHead ) ;
49- } else if ( typeof contentModuleHead === 'object' ) {
50- // Objects are merged inner over outer
51- resolveDocumentHead ( head , contentModuleHead ) ;
43+ const fns : Extract < ContentModuleHead , Function > [ ] = [ ] ;
44+ for ( const contentModule of contentModules ) {
45+ const contentModuleHead = contentModule ?. head ;
46+ if ( contentModuleHead ) {
47+ if ( typeof contentModuleHead === 'function' ) {
48+ // Functions are executed inner before outer
49+ fns . unshift ( contentModuleHead ) ;
50+ } else if ( typeof contentModuleHead === 'object' ) {
51+ // Objects are merged inner over outer
52+ resolveDocumentHead ( head , contentModuleHead ) ;
53+ }
5254 }
5355 }
54- }
55- if ( fns . length ) {
56- const headProps : DocumentHeadProps = {
57- head,
58- withLocale : ( fn ) => withLocale ( locale , fn ) ,
59- resolveValue : getData ,
60- ...routeLocation ,
61- } ;
56+ if ( fns . length ) {
57+ const headProps : DocumentHeadProps = {
58+ head,
59+ withLocale : ( fn ) => fn ( ) ,
60+ resolveValue : getData ,
61+ ...routeLocation ,
62+ } ;
6263
63- withLocale ( locale , ( ) => {
6464 for ( const fn of fns ) {
6565 resolveDocumentHead ( head , fn ( headProps ) ) ;
6666 }
67- } ) ;
68- }
67+ }
6968
70- return head ;
71- } ;
69+ return head ;
70+ } ) ;
7271
7372const resolveDocumentHead = (
7473 resolvedHead : Editable < ResolvedDocumentHead > ,
0 commit comments