Skip to content

Commit 2167f84

Browse files
committed
🐛 empty class inheritance
1 parent 535f463 commit 2167f84

File tree

6 files changed

+47
-2
lines changed

6 files changed

+47
-2
lines changed

client/invoke.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import deserialize from '../shared/deserialize'
22
import prefix from '../shared/prefix'
33
import page from './page'
44
import worker from './worker'
5+
import client from './client'
56

67
export default function invoke(name, hash) {
78
return async function _invoke(params = {}) {
@@ -15,7 +16,8 @@ export default function invoke(name, hash) {
1516
let finalHash = hash === this.hash ? hash : `${hash}-${this.hash}`
1617
let url = `${worker.api}/${prefix}/${finalHash}/${name}.json`
1718
if (module.hot) {
18-
url = `${worker.api}/${prefix}/${this.__hashes[name]}/${finalHash}/${name}.json`
19+
const version = client.klasses[hash].__hashes[name]
20+
url = `${worker.api}/${prefix}/${version}/${finalHash}/${name}.json`
1921
}
2022
const body = JSON.stringify(params || {})
2123
const options = {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"sass-loader": "13.2.0",
4444
"style-loader": "^3.3.1",
4545
"swc-loader": "0.2.3",
46-
"swc-plugin-nullstack": "0.1.1",
46+
"swc-plugin-nullstack": "0.1.2",
4747
"terser-webpack-plugin": "5.3.6",
4848
"time-analytics-webpack-plugin": "^0.1.20",
4949
"webpack": "^5.0.0",

server/registry.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function bindStaticProps(klass) {
1919
while (parent !== Nullstack) {
2020
const props = Object.getOwnPropertyNames(parent)
2121
for (const prop of props) {
22+
if (prop === 'caller' || prop === 'callee' || prop === 'arguments') continue
2223
const underscored = prop.startsWith('_')
2324
if (typeof klass[prop] === 'function') {
2425
if (!underscored && !registry[`${parent.hash}.${prop}`]) {

tests/src/Application.njs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import WorkerVerbs from './WorkerVerbs'
5959
import LazyComponent from './LazyComponent'
6060
import LazyComponentLoader from './LazyComponentLoader'
6161
import NestedFolder from './nested/NestedFolder'
62+
import ChildComponentWithoutServerFunctions from './ChildComponentWithoutServerFunctions'
6263
import './Application.css'
6364

6465
class Application extends Nullstack {
@@ -148,6 +149,7 @@ class Application extends Nullstack {
148149
<Logo route="/logo" />
149150
<NestedFolder route="/nested/folder" />
150151
<LazyComponent route="/lazy-importer" prop="works" />
152+
<ChildComponentWithoutServerFunctions route="/child-component-without-server-functions" />
151153
<ErrorPage route="*" />
152154
</body>
153155
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import ParentComponent from './ParentComponent'
2+
3+
class ChildComponentWithoutServerFunctions extends ParentComponent {
4+
5+
async initiate() {
6+
this.parentThis = await this.getParentThis()
7+
}
8+
9+
async hydrate() {
10+
this.hydratedParentThis = await this.getParentThis()
11+
}
12+
13+
render() {
14+
return (
15+
<div>
16+
<div data-parent-this={this.parentThis === this.constructor.name} />
17+
<div data-hydrated-parent-this={this.hydratedParentThis === this.constructor.name} />
18+
</div>
19+
)
20+
}
21+
22+
}
23+
24+
export default ChildComponentWithoutServerFunctions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
beforeAll(async () => {
2+
await page.goto('http://localhost:6969/child-component-without-server-functions')
3+
})
4+
5+
describe('ChildComponentWithoutServerFunctions', () => {
6+
test('inherited server functions are bound to the class ssr', async () => {
7+
const element = await page.$('[data-parent-this]')
8+
expect(element).toBeTruthy()
9+
})
10+
11+
test('inherited server functions are bound to the class spa', async () => {
12+
await page.waitForSelector('[data-hydrated-parent-this]')
13+
const element = await page.$('[data-hydrated-parent-this]')
14+
expect(element).toBeTruthy()
15+
})
16+
})

0 commit comments

Comments
 (0)