@invisibleloop/pulse 0.6.0 → 0.6.1
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/package.json
CHANGED
package/public/.pulse-ui-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.6.
|
|
1
|
+
0.6.1
|
package/src/runtime/ssr.js
CHANGED
|
@@ -146,7 +146,7 @@ export function renderToStream(spec, ctx = {}, nonce = '') {
|
|
|
146
146
|
? Object.fromEntries(await Promise.all([...fetcherCache.entries()].map(async ([k, p]) => [k, await p])))
|
|
147
147
|
: {}
|
|
148
148
|
const mergedAllState = mergeStoreKeys(spec, allServerState, ctx.store)
|
|
149
|
-
if (Object.keys(mergedAllState).length > 0) {
|
|
149
|
+
if (spec.hydrate && Object.keys(mergedAllState).length > 0) {
|
|
150
150
|
controller.enqueue(encode(
|
|
151
151
|
`<script nonce="${nonce}">window.__PULSE_SERVER__ = ${JSON.stringify(mergedAllState)};</script>`
|
|
152
152
|
))
|
|
@@ -314,8 +314,9 @@ export function wrapDocument({ content, spec = {}, serverState = {}, storeState
|
|
|
314
314
|
: ''
|
|
315
315
|
|
|
316
316
|
// Serialise server state into the page so the client runtime can read it
|
|
317
|
-
// without making a second request
|
|
318
|
-
|
|
317
|
+
// without making a second request. Only needed when the page is hydrated —
|
|
318
|
+
// purely server-rendered pages have no JS to read it.
|
|
319
|
+
const serverStateScript = spec.hydrate && Object.keys(serverState).length > 0
|
|
319
320
|
? `<script nonce="${nonce}">window.__PULSE_SERVER__ = ${JSON.stringify(serverState)};</script>`
|
|
320
321
|
: ''
|
|
321
322
|
|
package/src/runtime/ssr.test.js
CHANGED
|
@@ -61,7 +61,8 @@ const counterSpec = {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
const serverDataSpec = {
|
|
64
|
-
route:
|
|
64
|
+
route: '/products',
|
|
65
|
+
hydrate: '/src/pages/products.js',
|
|
65
66
|
state: {},
|
|
66
67
|
server: {
|
|
67
68
|
products: async (ctx) => [
|
|
@@ -314,7 +315,8 @@ await test('stream.scope: shell does not wait for deferred-only fetchers', async
|
|
|
314
315
|
|
|
315
316
|
await test('stream.scope: __PULSE_SERVER__ includes state from all scoped fetchers', async () => {
|
|
316
317
|
const spec = {
|
|
317
|
-
route:
|
|
318
|
+
route: '/scoped-state',
|
|
319
|
+
hydrate: '/src/pages/scoped-state.js',
|
|
318
320
|
stream: {
|
|
319
321
|
shell: ['header'],
|
|
320
322
|
deferred: ['feed'],
|
|
@@ -366,6 +368,7 @@ await test('sets og:title meta tag', async () => {
|
|
|
366
368
|
await test('serialises server state into page', async () => {
|
|
367
369
|
const { html } = wrapDocument({
|
|
368
370
|
content: '',
|
|
371
|
+
spec: { hydrate: '/src/pages/products.js' },
|
|
369
372
|
serverState: { products: [{ id: 1 }] }
|
|
370
373
|
})
|
|
371
374
|
assert(html.includes('__PULSE_SERVER__'), `Expected server state script: ${html}`)
|