Skip to content
Merged
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
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.12.3",
"version": "0.12.4",
"description": "Full-stack Javascript Components for one-dev armies",
"main": "nullstack.js",
"author": "Mortaro",
Expand Down
2 changes: 2 additions & 0 deletions tests/src/Application.njs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Instanceable from './Instanceable';
import InstanceKey from './InstanceKey';
import InstanceSelf from './InstanceSelf';
import IsomorphicStartup from './IsomorphicStartup';
import LazyComponentLoader from './LazyComponentLoader';
import NestedProxy from './NestedProxy';
import ParentComponent from './ParentComponent';
import PersistentComponent from './PersistentComponent';
Expand Down Expand Up @@ -91,6 +92,7 @@ class Application extends Nullstack {
<UnderscoredAttributes route="/underscored-attributes" />
<IsomorphicStartup route="/isomorphic-startup" />
<WorkerVerbs route="/worker-verbs" />
<LazyComponentLoader route="/lazy-component" />
<ErrorPage route="*" />
</main>
)
Expand Down
13 changes: 13 additions & 0 deletions tests/src/LazyComponent.njs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Nullstack from 'nullstack';

class LazyComponent extends Nullstack {

render() {
return (
<div data-lazy> LazyComponent </div>
)
}

}

export default LazyComponent;
24 changes: 24 additions & 0 deletions tests/src/LazyComponent.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const puppeteer = require('puppeteer');

let browser;
let page;

beforeAll(async () => {
browser = await puppeteer.launch();
page = await browser.newPage();
await page.goto('http://localhost:6969/lazy-component');
});

describe('LazyComponent', () => {

test('components can be lazy loaded', async () => {
await page.waitForSelector('[data-lazy]');
const element = await page.$('[data-lazy]');
expect(element).toBeTruthy();
});

});

afterAll(async () => {
browser.close();
});
18 changes: 18 additions & 0 deletions tests/src/LazyComponentLoader.njs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Nullstack from 'nullstack';

let LazyComponent

class LazyComponentLoader extends Nullstack {

async hydrate() {
LazyComponent = (await import('./LazyComponent')).default
}

render({ self }) {
if (!self.hydrated) return false
return <LazyComponent />
}

}

export default LazyComponentLoader;
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ function client(env, argv) {
mode: argv.environment,
entry: './client.js',
output: {
// publicPath: `/nullstack/${buildKey}/`,
publicPath: `/`,
path: path.resolve(__dirname, dir + '/' + folder + '/'),
filename: 'client.js'
},
Expand Down