Skip to content
Merged

Next #205

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions builders/ssg.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@ module.exports = async function ssg({ output, cache }) {
writeFileSync(`${target}.html`, content)
}

const instancesLookup = 'window.instances = ';
const instances = content.split("\n").find((line) => line.indexOf(instancesLookup) > -1).split(instancesLookup)[1].slice(0, -1);
const stateLookup = '<meta name="nullstack" content="';
const state = content.split("\n").find((line) => line.indexOf(stateLookup) > -1).split(stateLookup)[1].slice(0, -2);
const { instances, page } = JSON.parse(decodeURIComponent(state));

const pageLookup = 'window.page = ';
const page = content.split("\n").find((line) => line.indexOf(pageLookup) > -1).split(pageLookup)[1].slice(0, -1);
if (url !== `/nullstack/${application.environment.key}/offline` && url !== '/404') {
pages[url] = JSON.parse(page);
pages[url] = page;
}

const json = `{"instances": ${instances}, "page": ${page}}`;
const json = JSON.stringify({ instances, page });
writeFileSync(`${target}/index.json`, json);

const pattern = /href="(.*?)"/g;
Expand Down
2 changes: 1 addition & 1 deletion client/state.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import deserialize from '../shared/deserialize';

const state = deserialize(decodeURI(document.querySelector(`[name=nullstack]`).content));
const state = deserialize(decodeURIComponent(document.querySelector(`[name=nullstack]`).content));

export default state;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nullstack",
"version": "0.15.0",
"version": "0.15.1",
"description": "Full-stack Javascript Components for one-dev armies",
"main": "nullstack.js",
"author": "Mortaro",
Expand Down
2 changes: 1 addition & 1 deletion server/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default function ({ head, body, context, instances }) {
${page.schema ? `<script type="application/ld+json">${JSON.stringify(page.schema)}</script>` : ''}
${project.icons['180'] ? `<link rel="apple-touch-icon" sizes="180x180" href="${cdn(project.icons['180'])}">` : ''}
<meta name="msapplication-TileColor" content="${project.backgroundColor || project.color}">
<meta name="nullstack" content="${encodeURI(sanitizeString(JSON.stringify(state)))}">
<meta name="nullstack" content="${encodeURIComponent(sanitizeString(JSON.stringify(state)))}">
${head.split('<!--#-->').join('')}
<script src="${cdn(`/client.js?fingerprint=${environment.key}${timestamp}`)}" integrity="${integrities['client.js'] || ''}" defer crossorigin="anonymous"></script>
</head>
Expand Down
20 changes: 10 additions & 10 deletions tests/src/RenderableComponent.njs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class RenderableComponent extends Nullstack {
return <div data-nested />
}

renderInnerComponent({children}) {
renderInnerComponent({ children }) {
return (
<div class="InnerComponent">
<p> Inner Component </p>
Expand All @@ -19,14 +19,14 @@ class RenderableComponent extends Nullstack {
renderFalsy() {
return false;
}
render({params}) {
const list = params.shortList ? [1,2,3] : [1, 2, 3, 4, 5, 6]
const html = '<a href="/"> Nullstack </a>';

render({ params }) {
const list = params.shortList ? [1, 2, 3] : [1, 2, 3, 4, 5, 6]
const html = '<a href="/"> "Nullstack" </a>';
return (
<div class="RenderableComponent">
<Falsy />
<div data-object={{a: 1}} />
<div data-object={{ a: 1 }} />
<div data-function={RenderableComponent} />
<div> this is a normal tag </div>
<label for="input"> label </label>
Expand All @@ -37,7 +37,7 @@ class RenderableComponent extends Nullstack {
<element class="element" tag={params.condition ? 'div' : 'span'}>
element tag
</element>
<InnerComponent>
<InnerComponent>
<span class="children"> children </span>
</InnerComponent>
<ul>
Expand All @@ -47,11 +47,11 @@ class RenderableComponent extends Nullstack {
<head>
<link rel="preload" href="https://nullstack.app" as="fetch" crossorigin />
</head>
{!!params.condition &&
{!!params.condition &&
<div class="condition"> conditionally rendered div </div>
}
<a params={{shortList: true}} class="short-list"> long list </a>
<a params={{condition: true}} class="true-condition"> long list </a>
<a params={{ shortList: true }} class="short-list"> long list </a>
<a params={{ condition: true }} class="true-condition"> long list </a>
<div data-condition={!!params.condition} />
<div data-short-list={!!params.shortList} />
<div data-name={this.name} />
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function server(env, argv) {
nodeArgs: ['--enable-source-maps'],
quiet: true
})
]) : undefined;
]) : [];
return {
mode: argv.environment,
entry: './server.js',
Expand Down
9 changes: 4 additions & 5 deletions workers/staticHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ function withAPI(url) {

async function extractData(response) {
const html = await response.clone().text();
const instancesLookup = 'window.instances = ';
const instances = html.split("\n").find((line) => line.indexOf(instancesLookup) > -1).split(instancesLookup)[1].slice(0, -1);
const pageLookup = 'window.page = ';
const page = html.split("\n").find((line) => line.indexOf(pageLookup) > -1).split(pageLookup)[1].slice(0, -1);
const json = `{"instances": ${instances}, "page": ${page}}`;
const stateLookup = '<meta name="nullstack" content="';
const state = html.split("\n").find((line) => line.indexOf(stateLookup) > -1).split(stateLookup)[1].slice(0, -2);
const { instances, page } = JSON.parse(decodeURI(state));
const json = JSON.stringify({ instances, page });
return new Response(json, {
headers: { 'Content-Type': 'application/json' }
});
Expand Down