@bleedingdev/modern-js-runtime-renderer-extensions 3.9.0-ultramodern.8 → 3.9.0-ultramodern.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -37,6 +37,7 @@ var __webpack_require__ = {};
|
|
|
37
37
|
var __webpack_exports__ = {};
|
|
38
38
|
__webpack_require__.r(__webpack_exports__);
|
|
39
39
|
__webpack_require__.d(__webpack_exports__, {
|
|
40
|
+
RENDERER_HEAD_PRE_PLUGINS: ()=>RENDERER_HEAD_PRE_PLUGINS,
|
|
40
41
|
createRendererHeadPlugin: ()=>createRendererHeadPlugin,
|
|
41
42
|
default: ()=>runtimePlugin,
|
|
42
43
|
rendererHeadPlugin: ()=>rendererHeadPlugin
|
|
@@ -57,7 +58,7 @@ function createRendererHeadPlugin(options = {}) {
|
|
|
57
58
|
api.resolveComponent((component, { name })=>'head.Helmet' === name ? head.Head : component);
|
|
58
59
|
api.transformRuntimeContext(context_projection_namespaceObject.projectRuntimeContext);
|
|
59
60
|
api.wrapRoot((Root)=>{
|
|
60
|
-
const HeadRoot = (props)=>head.wrapClientRoot(external_react_default().createElement(Root, props));
|
|
61
|
+
const HeadRoot = (props)=>head.wrapClientRoot(Root ? external_react_default().createElement(Root, props) : props?.children ?? null);
|
|
61
62
|
return HeadRoot;
|
|
62
63
|
});
|
|
63
64
|
const createState = (runtimeContext)=>{
|
|
@@ -116,12 +117,23 @@ function createRendererHeadPlugin(options = {}) {
|
|
|
116
117
|
}
|
|
117
118
|
};
|
|
118
119
|
}
|
|
119
|
-
const
|
|
120
|
+
const RENDERER_HEAD_PRE_PLUGINS = [
|
|
121
|
+
'@modern-js/plugin-router',
|
|
122
|
+
'@modern-js/plugin-tanstack',
|
|
123
|
+
'@modern-js/plugin-state',
|
|
124
|
+
'@modern-js/plugin-i18n'
|
|
125
|
+
];
|
|
126
|
+
const rendererHeadPlugin = ()=>({
|
|
127
|
+
...createRendererHeadPlugin(),
|
|
128
|
+
pre: RENDERER_HEAD_PRE_PLUGINS
|
|
129
|
+
});
|
|
120
130
|
const runtimePlugin = rendererHeadPlugin;
|
|
131
|
+
exports.RENDERER_HEAD_PRE_PLUGINS = __webpack_exports__.RENDERER_HEAD_PRE_PLUGINS;
|
|
121
132
|
exports.createRendererHeadPlugin = __webpack_exports__.createRendererHeadPlugin;
|
|
122
133
|
exports["default"] = __webpack_exports__["default"];
|
|
123
134
|
exports.rendererHeadPlugin = __webpack_exports__.rendererHeadPlugin;
|
|
124
135
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
136
|
+
"RENDERER_HEAD_PRE_PLUGINS",
|
|
125
137
|
"createRendererHeadPlugin",
|
|
126
138
|
"default",
|
|
127
139
|
"rendererHeadPlugin"
|
|
@@ -13,7 +13,7 @@ function createRendererHeadPlugin(options = {}) {
|
|
|
13
13
|
api.resolveComponent((component, { name })=>'head.Helmet' === name ? head.Head : component);
|
|
14
14
|
api.transformRuntimeContext(projectRuntimeContext);
|
|
15
15
|
api.wrapRoot((Root)=>{
|
|
16
|
-
const HeadRoot = (props)=>head.wrapClientRoot(react.createElement(Root, props));
|
|
16
|
+
const HeadRoot = (props)=>head.wrapClientRoot(Root ? react.createElement(Root, props) : props?.children ?? null);
|
|
17
17
|
return HeadRoot;
|
|
18
18
|
});
|
|
19
19
|
const createState = (runtimeContext)=>{
|
|
@@ -72,7 +72,16 @@ function createRendererHeadPlugin(options = {}) {
|
|
|
72
72
|
}
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
|
-
const
|
|
75
|
+
const RENDERER_HEAD_PRE_PLUGINS = [
|
|
76
|
+
'@modern-js/plugin-router',
|
|
77
|
+
'@modern-js/plugin-tanstack',
|
|
78
|
+
'@modern-js/plugin-state',
|
|
79
|
+
'@modern-js/plugin-i18n'
|
|
80
|
+
];
|
|
81
|
+
const rendererHeadPlugin = ()=>({
|
|
82
|
+
...createRendererHeadPlugin(),
|
|
83
|
+
pre: RENDERER_HEAD_PRE_PLUGINS
|
|
84
|
+
});
|
|
76
85
|
const runtimePlugin = rendererHeadPlugin;
|
|
77
86
|
export default runtimePlugin;
|
|
78
|
-
export { createRendererHeadPlugin, rendererHeadPlugin };
|
|
87
|
+
export { RENDERER_HEAD_PRE_PLUGINS, createRendererHeadPlugin, rendererHeadPlugin };
|
|
@@ -14,7 +14,7 @@ function createRendererHeadPlugin(options = {}) {
|
|
|
14
14
|
api.resolveComponent((component, { name })=>'head.Helmet' === name ? head.Head : component);
|
|
15
15
|
api.transformRuntimeContext(projectRuntimeContext);
|
|
16
16
|
api.wrapRoot((Root)=>{
|
|
17
|
-
const HeadRoot = (props)=>head.wrapClientRoot(react.createElement(Root, props));
|
|
17
|
+
const HeadRoot = (props)=>head.wrapClientRoot(Root ? react.createElement(Root, props) : props?.children ?? null);
|
|
18
18
|
return HeadRoot;
|
|
19
19
|
});
|
|
20
20
|
const createState = (runtimeContext)=>{
|
|
@@ -73,7 +73,16 @@ function createRendererHeadPlugin(options = {}) {
|
|
|
73
73
|
}
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
|
-
const
|
|
76
|
+
const RENDERER_HEAD_PRE_PLUGINS = [
|
|
77
|
+
'@modern-js/plugin-router',
|
|
78
|
+
'@modern-js/plugin-tanstack',
|
|
79
|
+
'@modern-js/plugin-state',
|
|
80
|
+
'@modern-js/plugin-i18n'
|
|
81
|
+
];
|
|
82
|
+
const rendererHeadPlugin = ()=>({
|
|
83
|
+
...createRendererHeadPlugin(),
|
|
84
|
+
pre: RENDERER_HEAD_PRE_PLUGINS
|
|
85
|
+
});
|
|
77
86
|
const runtimePlugin = rendererHeadPlugin;
|
|
78
87
|
export default runtimePlugin;
|
|
79
|
-
export { createRendererHeadPlugin, rendererHeadPlugin };
|
|
88
|
+
export { RENDERER_HEAD_PRE_PLUGINS, createRendererHeadPlugin, rendererHeadPlugin };
|
|
@@ -3,5 +3,11 @@ export type RendererHeadPluginOptions = {
|
|
|
3
3
|
processNodeStream?: (source: NodeJS.ReadWriteStream, context: object, terminalMarker: string) => NodeJS.ReadWriteStream;
|
|
4
4
|
};
|
|
5
5
|
export declare function createRendererHeadPlugin(options?: RendererHeadPluginOptions): RuntimePlugin<{}>;
|
|
6
|
+
/**
|
|
7
|
+
* The plugins whose root this one wraps. Declaring them keeps the head
|
|
8
|
+
* provider outside their trees no matter what order the CLI emitted the
|
|
9
|
+
* runtime descriptors in.
|
|
10
|
+
*/
|
|
11
|
+
export declare const RENDERER_HEAD_PRE_PLUGINS: string[];
|
|
6
12
|
export declare const rendererHeadPlugin: () => RuntimePlugin<{}>;
|
|
7
13
|
export default rendererHeadPlugin;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"directory": "packages/runtime/renderer-extensions"
|
|
12
12
|
},
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"version": "3.9.0-ultramodern.
|
|
14
|
+
"version": "3.9.0-ultramodern.9",
|
|
15
15
|
"engines": {
|
|
16
16
|
"node": ">=26.7.0"
|
|
17
17
|
},
|
|
@@ -36,13 +36,12 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.9.0-ultramodern.
|
|
40
|
-
"@modern-js/runtime-extensions": "npm:@bleedingdev/modern-js-runtime-extensions@3.9.0-ultramodern.
|
|
39
|
+
"@modern-js/plugin": "npm:@bleedingdev/modern-js-plugin@3.9.0-ultramodern.9",
|
|
40
|
+
"@modern-js/runtime-extensions": "npm:@bleedingdev/modern-js-runtime-extensions@3.9.0-ultramodern.9"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@modern-js/render": "npm:@bleedingdev/modern-js-render@3.9.0-ultramodern.
|
|
44
|
-
"@modern-js/
|
|
45
|
-
"@modern-js/tsconfig": "npm:@bleedingdev/modern-js-tsconfig@3.9.0-ultramodern.8",
|
|
43
|
+
"@modern-js/render": "npm:@bleedingdev/modern-js-render@3.9.0-ultramodern.9",
|
|
44
|
+
"@modern-js/tsconfig": "npm:@bleedingdev/modern-js-tsconfig@3.9.0-ultramodern.9",
|
|
46
45
|
"@rslib/core": "1.0.0",
|
|
47
46
|
"@scripts/rstest-config": "2.66.0",
|
|
48
47
|
"@testing-library/dom": "^10.4.1",
|
package/src/runtimePlugin.ts
CHANGED
|
@@ -39,7 +39,15 @@ export function createRendererHeadPlugin(
|
|
|
39
39
|
api.transformRuntimeContext(projectRuntimeContext);
|
|
40
40
|
api.wrapRoot(Root => {
|
|
41
41
|
const HeadRoot = (props: React.ComponentProps<typeof Root>) =>
|
|
42
|
-
|
|
42
|
+
// A root is only defined once the plugin that owns it (the router,
|
|
43
|
+
// for a file-system routes entry) has run. This plugin must keep
|
|
44
|
+
// working when it is registered before that one: it then wraps the
|
|
45
|
+
// children the later plugin hands it instead of a missing root.
|
|
46
|
+
head.wrapClientRoot(
|
|
47
|
+
Root
|
|
48
|
+
? React.createElement(Root, props)
|
|
49
|
+
: ((props as { children?: React.ReactNode })?.children ?? null),
|
|
50
|
+
);
|
|
43
51
|
return HeadRoot;
|
|
44
52
|
});
|
|
45
53
|
|
|
@@ -113,7 +121,21 @@ export function createRendererHeadPlugin(
|
|
|
113
121
|
};
|
|
114
122
|
}
|
|
115
123
|
|
|
116
|
-
|
|
117
|
-
|
|
124
|
+
/**
|
|
125
|
+
* The plugins whose root this one wraps. Declaring them keeps the head
|
|
126
|
+
* provider outside their trees no matter what order the CLI emitted the
|
|
127
|
+
* runtime descriptors in.
|
|
128
|
+
*/
|
|
129
|
+
export const RENDERER_HEAD_PRE_PLUGINS = [
|
|
130
|
+
'@modern-js/plugin-router',
|
|
131
|
+
'@modern-js/plugin-tanstack',
|
|
132
|
+
'@modern-js/plugin-state',
|
|
133
|
+
'@modern-js/plugin-i18n',
|
|
134
|
+
];
|
|
135
|
+
|
|
136
|
+
export const rendererHeadPlugin = (): RuntimePlugin<{}> => ({
|
|
137
|
+
...createRendererHeadPlugin(),
|
|
138
|
+
pre: RENDERER_HEAD_PRE_PLUGINS,
|
|
139
|
+
});
|
|
118
140
|
|
|
119
141
|
export default rendererHeadPlugin;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { renderToString } from 'react-dom/server';
|
|
3
|
+
import {
|
|
4
|
+
getGlobalInternalRuntimeContext,
|
|
5
|
+
setGlobalContext,
|
|
6
|
+
setGlobalInternalRuntimeContext,
|
|
7
|
+
} from '../../plugin-runtime/src/core/context';
|
|
8
|
+
import { registerPlugin } from '../../plugin-runtime/src/core/plugin';
|
|
9
|
+
import rendererHeadPlugin, {
|
|
10
|
+
RENDERER_HEAD_PRE_PLUGINS,
|
|
11
|
+
} from '../src/runtimePlugin';
|
|
12
|
+
|
|
13
|
+
const previousRuntime = getGlobalInternalRuntimeContext();
|
|
14
|
+
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
setGlobalInternalRuntimeContext(previousRuntime);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
/** A stand-in for the router: it owns the root for a file-system routes entry. */
|
|
20
|
+
const routerLikePlugin = (content: React.ReactNode) => ({
|
|
21
|
+
name: '@modern-js/plugin-router',
|
|
22
|
+
setup(api: any) {
|
|
23
|
+
api.wrapRoot((App: React.ComponentType<any> | undefined) => {
|
|
24
|
+
const RouterWrapper = (props: any) =>
|
|
25
|
+
App
|
|
26
|
+
? React.createElement(App, props, content)
|
|
27
|
+
: React.createElement(React.Fragment, null, content);
|
|
28
|
+
return RouterWrapper;
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const renderRoot = () => {
|
|
34
|
+
const hooks = getGlobalInternalRuntimeContext().hooks;
|
|
35
|
+
// `App` is undefined for a routes entry until the router defines it.
|
|
36
|
+
const Root = hooks.wrapRoot.call(undefined as any);
|
|
37
|
+
return renderToString(React.createElement(Root));
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
describe('renderer head root wrapping', () => {
|
|
41
|
+
beforeEach(() => {
|
|
42
|
+
setGlobalContext({ enableRsc: false });
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('declares the runtime plugins it must wrap', () => {
|
|
46
|
+
expect(RENDERER_HEAD_PRE_PLUGINS).toContain('@modern-js/plugin-router');
|
|
47
|
+
expect(rendererHeadPlugin().pre).toEqual(RENDERER_HEAD_PRE_PLUGINS);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('renders the router root when it is registered after the router', () => {
|
|
51
|
+
registerPlugin([
|
|
52
|
+
routerLikePlugin(React.createElement('main', null, 'routed')),
|
|
53
|
+
rendererHeadPlugin(),
|
|
54
|
+
]);
|
|
55
|
+
|
|
56
|
+
expect(renderRoot()).toContain('routed');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('still renders when its descriptor is emitted before the router', () => {
|
|
60
|
+
// The CLI appends the renderer descriptor first for a plain `appTools()`
|
|
61
|
+
// app. Without an undefined-root fallback this threw
|
|
62
|
+
// "Element type is invalid ... but got: undefined" during SSR.
|
|
63
|
+
registerPlugin([
|
|
64
|
+
rendererHeadPlugin(),
|
|
65
|
+
routerLikePlugin(React.createElement('main', null, 'routed')),
|
|
66
|
+
]);
|
|
67
|
+
|
|
68
|
+
expect(renderRoot()).toContain('routed');
|
|
69
|
+
});
|
|
70
|
+
});
|