@bleedingdev/modern-js-runtime-renderer-extensions 0.0.0 → 3.9.0-ultramodern.5

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.
Files changed (38) hide show
  1. package/LICENSE +21 -0
  2. package/dist/cjs/assetPolicy.js +89 -0
  3. package/dist/cjs/federatedCss.js +57 -0
  4. package/dist/cjs/node.js +53 -0
  5. package/dist/cjs/runtimePlugin.js +131 -0
  6. package/dist/cjs/templatePolicy.js +76 -0
  7. package/dist/esm/assetPolicy.mjs +48 -0
  8. package/dist/esm/federatedCss.mjs +19 -0
  9. package/dist/esm/runtimePlugin.mjs +78 -0
  10. package/dist/esm/templatePolicy.mjs +38 -0
  11. package/dist/esm-node/assetPolicy.mjs +49 -0
  12. package/dist/esm-node/federatedCss.mjs +20 -0
  13. package/dist/esm-node/node.mjs +11 -0
  14. package/dist/esm-node/runtimePlugin.mjs +79 -0
  15. package/dist/esm-node/templatePolicy.mjs +39 -0
  16. package/dist/types/assetPolicy.d.ts +19 -0
  17. package/dist/types/federatedCss.d.ts +6 -0
  18. package/dist/types/node.d.ts +3 -0
  19. package/dist/types/runtimePlugin.d.ts +7 -0
  20. package/dist/types/templatePolicy.d.ts +2 -0
  21. package/package.json +61 -7
  22. package/rslib.config.mts +19 -0
  23. package/rstest.config.mts +29 -0
  24. package/src/assetPolicy.ts +86 -0
  25. package/src/federatedCss.ts +43 -0
  26. package/src/node.ts +16 -0
  27. package/src/runtimePlugin.ts +119 -0
  28. package/src/templatePolicy.ts +69 -0
  29. package/tests/federatedCss.test.ts +80 -0
  30. package/tests/headRuntime.test.tsx +334 -0
  31. package/tests/nativeAssetPolicy.test.tsx +515 -0
  32. package/tests/nativeStreamHead.test.tsx +77 -0
  33. package/tests/nativeStringHead.test.tsx +128 -0
  34. package/tests/nativeTemplatePolicy.test.tsx +818 -0
  35. package/tests/runtimePlugin.test.tsx +37 -0
  36. package/tests/scriptOrder.security.test.ts +42 -0
  37. package/tsconfig.json +10 -0
  38. package/README.md +0 -3
@@ -0,0 +1,128 @@
1
+ import React from 'react';
2
+ import { RenderLevel } from '../../plugin-runtime/src/core/constants';
3
+ import { registerPlugin } from '../../plugin-runtime/src/core/plugin';
4
+ import { renderString } from '../../plugin-runtime/src/core/server/string';
5
+ import { Helmet } from '../../plugin-runtime/src/exports/head';
6
+ import { rendererHeadPlugin } from '../src/node';
7
+
8
+ describe('renderString', () => {
9
+ it('collects helmet data without falling back to client render', async () => {
10
+ const onErrorCalls: unknown[][] = [];
11
+ const runtimeContext = {
12
+ isBrowser: false,
13
+ requestContext: {},
14
+ context: {},
15
+ initialData: {},
16
+ __i18nData__: {},
17
+ ssrContext: {
18
+ request: {
19
+ params: {},
20
+ query: {},
21
+ pathname: '/',
22
+ host: 'localhost',
23
+ url: 'http://localhost/',
24
+ headers: {},
25
+ },
26
+ reporter: { sessionId: 'session-1' },
27
+ },
28
+ };
29
+
30
+ registerPlugin([rendererHeadPlugin()]);
31
+
32
+ const html = await renderString(
33
+ new Request('http://localhost/'),
34
+ React.createElement(
35
+ React.Fragment,
36
+ null,
37
+ React.createElement(
38
+ Helmet,
39
+ null,
40
+ React.createElement('title', null, 'Server Title'),
41
+ ),
42
+ React.createElement('main', null, 'SSR body'),
43
+ ),
44
+ {
45
+ resource: {
46
+ entryName: 'main',
47
+ htmlTemplate:
48
+ '<html><head><title>Default</title><!--<?- chunksMap.css ?>--></head><body><div id="root"><!--<?- html ?>--></div><!--<?- SSRDataScript ?>--><!--<?- chunksMap.js ?>--></body></html>',
49
+ routeManifest: {},
50
+ },
51
+ runtimeContext,
52
+ config: {},
53
+ onError: (...args: unknown[]) => {
54
+ onErrorCalls.push(args);
55
+ },
56
+ onTiming: () => {},
57
+ } as any,
58
+ );
59
+
60
+ expect(onErrorCalls).toHaveLength(0);
61
+ expect(html).toContain('<title data-rh="true">Server Title</title>');
62
+ expect(html).toContain('SSR body');
63
+ expect(html).toContain(`"renderLevel":${RenderLevel.SERVER_RENDER}`);
64
+ });
65
+ it('publishes only Helmet markers present in completed Suspense output', async () => {
66
+ registerPlugin([rendererHeadPlugin()]);
67
+ const never = new Promise<never>(() => {});
68
+ const SuspendForever = (): null => {
69
+ throw never;
70
+ };
71
+
72
+ const html = await renderString(
73
+ new Request('http://localhost/'),
74
+ <>
75
+ <Helmet>
76
+ <meta name="outside" content="committed" />
77
+ </Helmet>
78
+ <React.Suspense
79
+ fallback={
80
+ <>
81
+ <Helmet>
82
+ <meta name="fallback" content="committed" />
83
+ </Helmet>
84
+ fallback rendered
85
+ </>
86
+ }
87
+ >
88
+ <Helmet>
89
+ <meta name="abandoned-unique" content="ghost" />
90
+ </Helmet>
91
+ <SuspendForever />
92
+ </React.Suspense>
93
+ </>,
94
+ {
95
+ resource: {
96
+ entryName: 'index',
97
+ htmlTemplate:
98
+ '<html><head></head><body><!--<?- html ?>--></body></html>',
99
+ routeManifest: {},
100
+ },
101
+ runtimeContext: {
102
+ isBrowser: false,
103
+ initialData: {},
104
+ __i18nData__: {},
105
+ ssrContext: {
106
+ request: {
107
+ params: {},
108
+ query: {},
109
+ pathname: '/',
110
+ host: 'localhost',
111
+ url: 'http://localhost/',
112
+ headers: {},
113
+ },
114
+ reporter: { sessionId: 'session-1' },
115
+ },
116
+ },
117
+ config: {},
118
+ onError: () => {},
119
+ onTiming: () => {},
120
+ } as any,
121
+ );
122
+
123
+ expect(html).toContain('name="outside" content="committed"');
124
+ expect(html).toContain('name="fallback" content="committed"');
125
+ expect(html).not.toContain('abandoned-unique');
126
+ expect(html).not.toContain('data-modern-helmet');
127
+ });
128
+ });