@vyriy/render 0.4.7
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.
- package/AGENTS.md +102 -0
- package/LICENSE +21 -0
- package/README.md +129 -0
- package/custom-element.d.ts +2 -0
- package/custom-element.js +34 -0
- package/element.d.ts +2 -0
- package/element.js +18 -0
- package/errors.d.ts +2 -0
- package/errors.js +6 -0
- package/html.d.ts +2 -0
- package/html.js +2 -0
- package/index.d.ts +6 -0
- package/index.js +5 -0
- package/package.json +98 -0
- package/prerender.d.ts +3 -0
- package/prerender.js +7 -0
- package/stream.d.ts +2 -0
- package/stream.js +6 -0
- package/types.d.ts +33 -0
package/AGENTS.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# Project Agent Guide
|
|
2
|
+
|
|
3
|
+
This repository follows a calm engineering style: changes should be explicit, reusable, typed, documented, tested, and easy to reason about.
|
|
4
|
+
|
|
5
|
+
Use this guide as the default behavior for AI agents and contributors working in this repository. Prefer local package conventions when they are more specific than this document.
|
|
6
|
+
|
|
7
|
+
## Core Principles
|
|
8
|
+
|
|
9
|
+
- Prefer simple modules over clever frameworks or hidden conventions.
|
|
10
|
+
- Keep package and project boundaries explicit.
|
|
11
|
+
- Avoid project-specific coupling in reusable code.
|
|
12
|
+
- Extract only proven reusable behavior.
|
|
13
|
+
- Keep public APIs small, typed, documented, and stable.
|
|
14
|
+
- Prefer SSR-friendly and SSG-friendly code paths when working with frontend or shared code.
|
|
15
|
+
- Keep integrations replaceable and avoid hard coupling to a CMS, framework, vendor, or runtime host.
|
|
16
|
+
- Prefer infrastructure assumptions that are easy to deploy, observe, and replace.
|
|
17
|
+
- Prefer the option that is simpler to explain, easier to evolve, and calmer to maintain.
|
|
18
|
+
|
|
19
|
+
## File Shape
|
|
20
|
+
|
|
21
|
+
- Prefer one exported runtime method, component, helper, or class per production file when it stays readable.
|
|
22
|
+
- Prefer one matching test file per production file, for example `feature.ts` and `feature.test.ts`.
|
|
23
|
+
- Use focused folders when behavior naturally splits into several related files.
|
|
24
|
+
- Keep `index.ts` as a public re-export surface only. Do not place implementation logic in it.
|
|
25
|
+
- Use relative import and export specifiers that match the package module style.
|
|
26
|
+
- Use `.js` relative specifiers in TypeScript source for ESM/NodeNext packages.
|
|
27
|
+
- Add `types.ts` when public shared types are part of the package contract.
|
|
28
|
+
- Keep constants near the code that owns them unless they are shared or clarify repeated behavior.
|
|
29
|
+
|
|
30
|
+
## Public Surface
|
|
31
|
+
|
|
32
|
+
- Every new public export must be re-exported from the package or module public entry point.
|
|
33
|
+
- Add or update public-surface tests when exports change.
|
|
34
|
+
- Add JSDoc for public exports when behavior, parameters, return values, or usage expectations need explanation.
|
|
35
|
+
- Avoid exporting internal helpers only to make tests easier.
|
|
36
|
+
- Do not hand-maintain package `exports` maps unless the project has a real custom publishing need.
|
|
37
|
+
|
|
38
|
+
## Tests
|
|
39
|
+
|
|
40
|
+
- Cover public behavior and meaningful edge cases.
|
|
41
|
+
- Prefer behavior-focused tests over private implementation lock-in.
|
|
42
|
+
- Keep tests deterministic.
|
|
43
|
+
- Avoid real network, filesystem, timers, browser, or cloud dependencies unless the behavior specifically requires them.
|
|
44
|
+
- When mocking modules, install mocks before loading the module under test.
|
|
45
|
+
- Use focused validation when changing behavior.
|
|
46
|
+
|
|
47
|
+
Example validation commands:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
yarn test
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
For workspaces, prefer the project convention, for example:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
yarn workspace <package-name> test
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
For Jest-based packages, focused validation may look like:
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
yarn jest packages/<package> --runInBand --coverage=false
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Documentation
|
|
66
|
+
|
|
67
|
+
- Keep `README.md` concise and usage-oriented.
|
|
68
|
+
- Start package READMEs with `# <package>`.
|
|
69
|
+
- Document real public exports, supported options, and examples that actually work.
|
|
70
|
+
- Update docs when public behavior changes.
|
|
71
|
+
- Keep generated docs wrappers, such as `doc.mdx`, aligned with the README when the project uses them.
|
|
72
|
+
- For component packages, include visual documentation or stories for supported states and common usage.
|
|
73
|
+
|
|
74
|
+
## Components
|
|
75
|
+
|
|
76
|
+
- Prefer lightweight React components with TypeScript when working in React packages.
|
|
77
|
+
- Keep components SSR-friendly and avoid browser globals during render.
|
|
78
|
+
- Prefer composable props and predictable ergonomics.
|
|
79
|
+
- Put each public component in its own file with a matching test.
|
|
80
|
+
- Add stories or examples when a component has visual states, variants, or interaction states.
|
|
81
|
+
- Keep styling explicit and reusable. Avoid hidden theme assumptions unless they are part of the package contract.
|
|
82
|
+
|
|
83
|
+
## Change Discipline
|
|
84
|
+
|
|
85
|
+
- Keep changes scoped to the requested behavior.
|
|
86
|
+
- Avoid unrelated refactors and metadata churn.
|
|
87
|
+
- Sync implementation, tests, docs, examples, and public re-exports together.
|
|
88
|
+
- Do not introduce new dependencies unless they clearly reduce complexity or are already part of the project direction.
|
|
89
|
+
- Prefer small, reviewable changes over broad rewrites.
|
|
90
|
+
- Preserve existing conventions unless there is a clear reason to change them.
|
|
91
|
+
|
|
92
|
+
## Before Finishing
|
|
93
|
+
|
|
94
|
+
Check that the change is complete:
|
|
95
|
+
|
|
96
|
+
- Public exports are updated.
|
|
97
|
+
- Public-surface tests are updated when exports change.
|
|
98
|
+
- Matching unit tests exist for new behavior.
|
|
99
|
+
- README examples still match the real API.
|
|
100
|
+
- Visual docs, stories, or examples are updated for visible component behavior.
|
|
101
|
+
- TypeScript imports follow the package module style.
|
|
102
|
+
- No unrelated files, formatting churn, or generated artifacts were changed.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Vyriy contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
# @vyriy/render
|
|
2
|
+
|
|
3
|
+
Small explicit React rendering adapters for browser DOM rendering, hydration, custom elements, SSR, streaming SSR, and static generation.
|
|
4
|
+
|
|
5
|
+
`@vyriy/render` is not a framework. It wraps official React rendering APIs into small predictable helpers that are easy to use in Vyriy-style applications, MFEs, SSR pages, SSG pipelines, and custom elements.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
With npm:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @vyriy/render
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
With Yarn:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
yarn add @vyriy/render
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## API
|
|
22
|
+
|
|
23
|
+
| API | Purpose |
|
|
24
|
+
| --------------- | ----------------------------------------------------------------- |
|
|
25
|
+
| `element` | Render or hydrate a React component into an existing DOM element. |
|
|
26
|
+
| `customElement` | Register a custom element that renders a React component. |
|
|
27
|
+
| `html` | Render a React component to an HTML string. |
|
|
28
|
+
| `stream` | Render a React component to a Web `ReadableStream`. |
|
|
29
|
+
| `prerender` | Prerender a React component for static generation. |
|
|
30
|
+
|
|
31
|
+
Hydration auto-detection uses a `rendered` marker attribute by default.
|
|
32
|
+
|
|
33
|
+
## Browser rendering
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
import { element } from '@vyriy/render';
|
|
37
|
+
|
|
38
|
+
import { App } from './app.js';
|
|
39
|
+
|
|
40
|
+
element({
|
|
41
|
+
root: document.getElementById('root'),
|
|
42
|
+
component: <App />,
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Browser hydration
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
import { element } from '@vyriy/render';
|
|
50
|
+
|
|
51
|
+
import { App } from './app.js';
|
|
52
|
+
|
|
53
|
+
element({
|
|
54
|
+
root: document.getElementById('root'),
|
|
55
|
+
component: <App />,
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Server markup:
|
|
60
|
+
|
|
61
|
+
```html
|
|
62
|
+
<div id="root" rendered></div>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Custom element
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
import { customElement } from '@vyriy/render';
|
|
69
|
+
|
|
70
|
+
import { ProfileCard } from './profile-card.js';
|
|
71
|
+
|
|
72
|
+
customElement({
|
|
73
|
+
tag: 'vyriy-profile-card',
|
|
74
|
+
elements: () => {
|
|
75
|
+
const styles = document.createElement('style');
|
|
76
|
+
const container = document.createElement('div');
|
|
77
|
+
|
|
78
|
+
styles.textContent = '.profile-card { display: block; }';
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
elements: [styles, container],
|
|
82
|
+
root: container,
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
render: (customElement) => {
|
|
86
|
+
return <ProfileCard name={customElement.getAttribute('name') ?? ''} />;
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## HTML string
|
|
92
|
+
|
|
93
|
+
```tsx
|
|
94
|
+
import { html } from '@vyriy/render';
|
|
95
|
+
|
|
96
|
+
import { App } from './app.js';
|
|
97
|
+
|
|
98
|
+
const body = html(<App />);
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Stream
|
|
102
|
+
|
|
103
|
+
```tsx
|
|
104
|
+
import { stream } from '@vyriy/render';
|
|
105
|
+
|
|
106
|
+
import { App } from './app.js';
|
|
107
|
+
|
|
108
|
+
const htmlStream = await stream({
|
|
109
|
+
component: <App />,
|
|
110
|
+
bootstrapScripts: ['/assets/app.js'],
|
|
111
|
+
});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Rrerender
|
|
115
|
+
|
|
116
|
+
```tsx
|
|
117
|
+
import { prerender } from '@vyriy/render';
|
|
118
|
+
|
|
119
|
+
import { App } from './app.js';
|
|
120
|
+
|
|
121
|
+
const result = await prerender({
|
|
122
|
+
component: <App />,
|
|
123
|
+
bootstrapScripts: ['/assets/app.js'],
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Non-goals
|
|
128
|
+
|
|
129
|
+
This package intentionally does not provide routing, data loading, bundling, CSS handling, asset manifest loading, or application framework behavior.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createRoot, hydrateRoot } from 'react-dom/client';
|
|
2
|
+
import { createMissingCustomElementRootError } from './errors.js';
|
|
3
|
+
export const customElement = ({ tag, mode = 'open', renderedAttribute = 'rendered', elements, render, options = {}, }) => {
|
|
4
|
+
if (customElements.get(tag)) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
customElements.define(tag, class extends HTMLElement {
|
|
8
|
+
#root;
|
|
9
|
+
#mount;
|
|
10
|
+
constructor() {
|
|
11
|
+
super();
|
|
12
|
+
const shadow = this.attachShadow({ mode });
|
|
13
|
+
const renderElements = elements(this);
|
|
14
|
+
if (!renderElements.root) {
|
|
15
|
+
throw createMissingCustomElementRootError();
|
|
16
|
+
}
|
|
17
|
+
this.#mount = renderElements.root;
|
|
18
|
+
shadow.append(...renderElements.elements);
|
|
19
|
+
}
|
|
20
|
+
connectedCallback() {
|
|
21
|
+
const reactNode = render(this);
|
|
22
|
+
if (this.hasAttribute(renderedAttribute)) {
|
|
23
|
+
this.#root = hydrateRoot(this.#mount, reactNode, options);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
this.#root ??= createRoot(this.#mount, options);
|
|
27
|
+
this.#root.render(reactNode);
|
|
28
|
+
}
|
|
29
|
+
disconnectedCallback() {
|
|
30
|
+
this.#root?.unmount();
|
|
31
|
+
this.#root = undefined;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
};
|
package/element.d.ts
ADDED
package/element.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createRoot, hydrateRoot } from 'react-dom/client';
|
|
2
|
+
import { createMissingElementError } from './errors.js';
|
|
3
|
+
export const element = ({ root, component, renderedAttribute = 'rendered', options = {}, }) => {
|
|
4
|
+
if (!root) {
|
|
5
|
+
throw createMissingElementError();
|
|
6
|
+
}
|
|
7
|
+
const shouldHydrate = root.hasAttribute(renderedAttribute);
|
|
8
|
+
const reactRoot = shouldHydrate ? hydrateRoot(root, component, options) : createRoot(root, options);
|
|
9
|
+
if (!shouldHydrate) {
|
|
10
|
+
reactRoot.render(component);
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
root: reactRoot,
|
|
14
|
+
unmount: () => {
|
|
15
|
+
reactRoot.unmount();
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
};
|
package/errors.d.ts
ADDED
package/errors.js
ADDED
package/html.d.ts
ADDED
package/html.js
ADDED
package/index.d.ts
ADDED
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vyriy/render",
|
|
3
|
+
"version": "0.4.7",
|
|
4
|
+
"description": "React rendering adapters for Vyriy projects",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@types/react": "^19.2.15",
|
|
8
|
+
"@types/react-dom": "^19.2.3",
|
|
9
|
+
"react": "^19.2.6",
|
|
10
|
+
"react-dom": "^19.2.6"
|
|
11
|
+
},
|
|
12
|
+
"agents": "./AGENTS.md",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/evheniy/vyriy",
|
|
17
|
+
"directory": "packages/render"
|
|
18
|
+
},
|
|
19
|
+
"main": "./index.js",
|
|
20
|
+
"types": "./index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./index.d.ts",
|
|
24
|
+
"import": "./index.js",
|
|
25
|
+
"default": "./index.js"
|
|
26
|
+
},
|
|
27
|
+
"./custom-element": {
|
|
28
|
+
"types": "./custom-element.d.ts",
|
|
29
|
+
"import": "./custom-element.js",
|
|
30
|
+
"default": "./custom-element.js"
|
|
31
|
+
},
|
|
32
|
+
"./custom-element.js": {
|
|
33
|
+
"types": "./custom-element.d.ts",
|
|
34
|
+
"import": "./custom-element.js",
|
|
35
|
+
"default": "./custom-element.js"
|
|
36
|
+
},
|
|
37
|
+
"./element": {
|
|
38
|
+
"types": "./element.d.ts",
|
|
39
|
+
"import": "./element.js",
|
|
40
|
+
"default": "./element.js"
|
|
41
|
+
},
|
|
42
|
+
"./element.js": {
|
|
43
|
+
"types": "./element.d.ts",
|
|
44
|
+
"import": "./element.js",
|
|
45
|
+
"default": "./element.js"
|
|
46
|
+
},
|
|
47
|
+
"./errors": {
|
|
48
|
+
"types": "./errors.d.ts",
|
|
49
|
+
"import": "./errors.js",
|
|
50
|
+
"default": "./errors.js"
|
|
51
|
+
},
|
|
52
|
+
"./errors.js": {
|
|
53
|
+
"types": "./errors.d.ts",
|
|
54
|
+
"import": "./errors.js",
|
|
55
|
+
"default": "./errors.js"
|
|
56
|
+
},
|
|
57
|
+
"./html": {
|
|
58
|
+
"types": "./html.d.ts",
|
|
59
|
+
"import": "./html.js",
|
|
60
|
+
"default": "./html.js"
|
|
61
|
+
},
|
|
62
|
+
"./html.js": {
|
|
63
|
+
"types": "./html.d.ts",
|
|
64
|
+
"import": "./html.js",
|
|
65
|
+
"default": "./html.js"
|
|
66
|
+
},
|
|
67
|
+
"./index": {
|
|
68
|
+
"types": "./index.d.ts",
|
|
69
|
+
"import": "./index.js",
|
|
70
|
+
"default": "./index.js"
|
|
71
|
+
},
|
|
72
|
+
"./index.js": {
|
|
73
|
+
"types": "./index.d.ts",
|
|
74
|
+
"import": "./index.js",
|
|
75
|
+
"default": "./index.js"
|
|
76
|
+
},
|
|
77
|
+
"./prerender": {
|
|
78
|
+
"types": "./prerender.d.ts",
|
|
79
|
+
"import": "./prerender.js",
|
|
80
|
+
"default": "./prerender.js"
|
|
81
|
+
},
|
|
82
|
+
"./prerender.js": {
|
|
83
|
+
"types": "./prerender.d.ts",
|
|
84
|
+
"import": "./prerender.js",
|
|
85
|
+
"default": "./prerender.js"
|
|
86
|
+
},
|
|
87
|
+
"./stream": {
|
|
88
|
+
"types": "./stream.d.ts",
|
|
89
|
+
"import": "./stream.js",
|
|
90
|
+
"default": "./stream.js"
|
|
91
|
+
},
|
|
92
|
+
"./stream.js": {
|
|
93
|
+
"types": "./stream.d.ts",
|
|
94
|
+
"import": "./stream.js",
|
|
95
|
+
"default": "./stream.js"
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
package/prerender.d.ts
ADDED
package/prerender.js
ADDED
package/stream.d.ts
ADDED
package/stream.js
ADDED
package/types.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { Root, RootOptions } from 'react-dom/client';
|
|
3
|
+
export type ElementOptions = {
|
|
4
|
+
root: Element | null;
|
|
5
|
+
component: ReactNode;
|
|
6
|
+
renderedAttribute?: string;
|
|
7
|
+
options?: RootOptions;
|
|
8
|
+
};
|
|
9
|
+
export type ElementResult = {
|
|
10
|
+
root: Root;
|
|
11
|
+
unmount: () => void;
|
|
12
|
+
};
|
|
13
|
+
export type CustomElementRenderElements = {
|
|
14
|
+
elements: readonly Node[];
|
|
15
|
+
root: Element | null;
|
|
16
|
+
};
|
|
17
|
+
export type CustomElementOptions = {
|
|
18
|
+
tag: string;
|
|
19
|
+
mode?: ShadowRootMode;
|
|
20
|
+
renderedAttribute?: string;
|
|
21
|
+
elements: (customElement: HTMLElement) => CustomElementRenderElements;
|
|
22
|
+
render: (customElement: HTMLElement) => ReactNode;
|
|
23
|
+
options?: RootOptions;
|
|
24
|
+
};
|
|
25
|
+
export type Html = (component: ReactNode) => string;
|
|
26
|
+
export type StreamOptions = {
|
|
27
|
+
component: ReactNode;
|
|
28
|
+
bootstrapScripts?: string[];
|
|
29
|
+
};
|
|
30
|
+
export type PrerenderOptions = {
|
|
31
|
+
component: ReactNode;
|
|
32
|
+
bootstrapScripts?: string[];
|
|
33
|
+
};
|