@soleil-se/app-util 4.1.2 → 4.1.3
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/CHANGELOG.md +7 -0
- package/client/.eslintrc.js +4 -0
- package/docs/2.svelte.md +26 -0
- package/package.json +2 -2
- package/server/svelte/index.js +10 -6
- package/client/.eslintrc +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [4.1.3] - 2021-03-31
|
|
8
|
+
### Fixed
|
|
9
|
+
- Consistent rendering when using `serverServer` and `render` for Svelte.
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
- Docs for Svelte `renderServer` function.
|
|
13
|
+
|
|
7
14
|
## [4.1.2] - 2021-02-24
|
|
8
15
|
### Fixed
|
|
9
16
|
- Escape tags when parsing data to prevent closure of script tags.
|
package/docs/2.svelte.md
CHANGED
|
@@ -14,6 +14,7 @@ If a client bundle is available the server rendered HTML will be hydrated and no
|
|
|
14
14
|
|
|
15
15
|
| Param | Type | Default | Description |
|
|
16
16
|
| --- | --- | --- | --- |
|
|
17
|
+
| [App] | <code>Svelte</code> | | Svelte app to be rendered. |
|
|
17
18
|
| [props] | <code>Object</code> | <code>{}</code> | Server data that will be available as props and as app data. |
|
|
18
19
|
| [settings] | <code>Object</code> | <code>{}</code> | Settings object. Forwarded to |
|
|
19
20
|
| [settings.async] | <code>Boolean</code> | <code>false</code> | If the app script should be loaded asynchronously. |
|
|
@@ -35,6 +36,31 @@ router.get('/', (req, res) => {
|
|
|
35
36
|
});
|
|
36
37
|
```
|
|
37
38
|
|
|
39
|
+
### `renderServer(App, [props])`
|
|
40
|
+
`@soleil-api/webapp-util/server/svelte`
|
|
41
|
+
|
|
42
|
+
Get a HTML string for rendering a server side Svelte application.
|
|
43
|
+
|
|
44
|
+
**Returns**: <code>String</code> - HTML for rendering a Svelte application.
|
|
45
|
+
|
|
46
|
+
| Param | Type | Default | Description |
|
|
47
|
+
| --- | --- | --- | --- |
|
|
48
|
+
| [App] | <code>Svelte</code> | | Svelte app to be rendered. |
|
|
49
|
+
| [props] | <code>Object</code> | <code>{}</code> | Server data that will be available as props and as app data. |
|
|
50
|
+
|
|
51
|
+
In `app_src/index.js` or `app_src/server/index.js`.
|
|
52
|
+
```javascript
|
|
53
|
+
import router from 'router';
|
|
54
|
+
import { renderServer } from '@soleil-api/webapp-util/server/svelte';
|
|
55
|
+
|
|
56
|
+
import App from './App.svelte';
|
|
57
|
+
|
|
58
|
+
router.get('/', (req, res) => {
|
|
59
|
+
const props = { foo: 'bar' };
|
|
60
|
+
res.send(render(App, data));
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
38
64
|
## main.js
|
|
39
65
|
|
|
40
66
|
### `render(App, [settings])`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soleil-se/app-util",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.3",
|
|
4
4
|
"description": "Utility functions for Webapps.",
|
|
5
5
|
"main": "./common/index.js",
|
|
6
6
|
"author": "Soleil AB",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"optionalDependencies": {
|
|
15
15
|
"vue": "^2.6.11"
|
|
16
16
|
},
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "9fc1fba75e8419058746c7170dcf96ea6c78f4eb",
|
|
18
18
|
"dependencies": {},
|
|
19
19
|
"devDependencies": {}
|
|
20
20
|
}
|
package/server/svelte/index.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
/* eslint-disable import/prefer-default-export */
|
|
2
2
|
import appResource from 'appResource';
|
|
3
|
-
import { setAppData } from '../../common';
|
|
3
|
+
import { appId, setAppData } from '../../common';
|
|
4
4
|
import { render as renderClient } from '../index';
|
|
5
5
|
|
|
6
|
+
const initSSR = (App, props) => {
|
|
7
|
+
setAppData(props);
|
|
8
|
+
return App.render(props).html;
|
|
9
|
+
};
|
|
10
|
+
|
|
6
11
|
/**
|
|
7
12
|
* SSR Svelte App.
|
|
8
13
|
* @export
|
|
@@ -11,9 +16,8 @@ import { render as renderClient } from '../index';
|
|
|
11
16
|
* @return {String} - HTML for rendering a Svelte application.
|
|
12
17
|
*/
|
|
13
18
|
export function renderServer(App, props = {}) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return html;
|
|
19
|
+
const html = initSSR(App, props);
|
|
20
|
+
return `<div id="app_mount_${appId}">${html}</div>`;
|
|
17
21
|
}
|
|
18
22
|
|
|
19
23
|
/**
|
|
@@ -25,9 +29,9 @@ export function renderServer(App, props = {}) {
|
|
|
25
29
|
* @return {String} - HTML for rendering a Svelte application.
|
|
26
30
|
*/
|
|
27
31
|
export function render(App, props = {}, settings) {
|
|
28
|
-
const html =
|
|
32
|
+
const html = initSSR(App, props);
|
|
29
33
|
if (appResource.getNode('client/index.js')) {
|
|
30
34
|
return renderClient(props, { ...settings, html });
|
|
31
35
|
}
|
|
32
|
-
return html
|
|
36
|
+
return `<div id="app_mount_${appId}">${html}</div>`;
|
|
33
37
|
}
|
package/client/.eslintrc
DELETED