GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — :zap^Cfaster head and textarea · nullstack/nullstack@7758cca

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • client
    • hydrate.js
    • index.js
    • render.js
    • rerender.js
  • shared
    • generateTree.js
  • tests
    • jest-puppeteer.config.js
    • src
      • DynamicHead.njs
      • DynamicHead.test.js
      • StatefulComponent.njs
      • StatefulComponent.test.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎client/hydrate.js‎

Copy file name to clipboardExpand all lines: client/hydrate.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { anchorableElement } from './anchorableNode';
22

33
export default function hydrate(selector, node) {
4-
if (node?.attributes?.['data-n'] !== undefined) {
5-
node.element = document.querySelector(`[data-n="${node.attributes['data-n']}"]`)
4+
if (node.head) {
5+
node.element = document.getElementById(node.attributes.id)
66
return
77
}
88
if (node?.attributes?.html) {
Collapse file

‎client/index.js‎

Copy file name to clipboardExpand all lines: client/index.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export default class Nullstack {
5252
updateParams(router.url);
5353
client.currentInstance = null;
5454
client.initializer = () => element(Starter);
55-
client.selector = document.querySelector('#application');
55+
client.selector = document.getElementById('application');
5656
if (environment.mode === 'spa') {
5757
scope.plugins = loadPlugins(scope);
5858
worker.online = navigator.onLine;
Collapse file

‎client/render.js‎

Copy file name to clipboardExpand all lines: client/render.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default function render(node, options) {
2929
for (let name in node.attributes) {
3030
if (name === 'html') {
3131
node.element.innerHTML = node.attributes[name];
32-
node.attributes['data-n'] === undefined && anchorableElement(node.element);
32+
node.head || anchorableElement(node.element);
3333
} else if (name.startsWith('on')) {
3434
if (node.attributes[name] !== undefined) {
3535
const eventName = name.substring(2);
Collapse file

‎client/rerender.js‎

Copy file name to clipboardExpand all lines: client/rerender.js
+8-9Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,15 @@ function _rerender(current, next) {
8888
const limit = next.children.length;
8989
for (let i = limit - 1; i > -1; i--) {
9090
const nextSelector = render(next.children[i]);
91-
document.querySelector('head').appendChild(nextSelector)
91+
document.head.appendChild(nextSelector)
9292
}
9393
return
9494
}
9595

9696
if (current.type === 'head' && next.type !== 'head') {
9797
const limit = current.children.length;
9898
for (let i = limit - 1; i > -1; i--) {
99-
document.querySelector(`[data-n="${current.children[i].attributes['data-n']}"]`).remove()
99+
current.children[i].element.remove()
100100
}
101101
return
102102
}
@@ -106,22 +106,21 @@ function _rerender(current, next) {
106106
for (let i = limit - 1; i > -1; i--) {
107107
if (isUndefined(current.children[i]) && !isFalse(next.children[i])) {
108108
const nextSelector = render(next.children[i]);
109-
document.querySelector('head').appendChild(nextSelector)
109+
document.head.appendChild(nextSelector)
110110
} else if (isUndefined(next.children[i]) && !isFalse(current.children[i])) {
111111
current.children[i].element.remove()
112112
} else if (!isFalse(current.children[i]) && !isFalse(next.children[i])) {
113113
if (current.children[i].type === next.children[i].type) {
114114
next.children[i].element = current.children[i].element
115-
const element = document.querySelector(`[data-n="${next.children[i].attributes['data-n']}"]`)
116-
updateAttributes(element, current.children[i], next.children[i])
115+
updateAttributes(current.children[i].element, current.children[i], next.children[i])
117116
} else {
118-
document.querySelector(`[data-n="${current.children[i].attributes['data-n']}"]`).remove()
117+
current.children[i].element.remove()
119118
const nextSelector = render(next.children[i]);
120-
document.querySelector('head').appendChild(nextSelector)
119+
document.head.appendChild(nextSelector)
121120
}
122121
} else if (isFalse(current.children[i]) && !isFalse(next.children[i])) {
123122
const nextSelector = render(next.children[i]);
124-
document.querySelector('head').appendChild(nextSelector)
123+
document.head.appendChild(nextSelector)
125124
} else if (current.children[i].type) {
126125
current.children[i].element.remove()
127126
}
@@ -177,7 +176,7 @@ function _rerender(current, next) {
177176
}
178177

179178
if (next.type == 'textarea') {
180-
selector.value = next.children.reduce((t, c) => t + c.text, '');
179+
selector.value = next.children[0].text;
181180
}
182181

183182
if (next.type == 'select') {
Collapse file

‎shared/generateTree.js‎

Copy file name to clipboardExpand all lines: shared/generateTree.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ async function generateBranch(parent, node, depth, scope) {
130130
if (node.type === 'head') {
131131
for (let i = 0; i < branch.children.length; i++) {
132132
if (branch.children[i].attributes) {
133-
branch.children[i].attributes['data-n'] = depth + '-' + i
133+
branch.children[i].head = true
134+
branch.children[i].attributes.id = depth + '-' + i
134135
}
135136
}
136137
}
Collapse file

‎tests/jest-puppeteer.config.js‎

Copy file name to clipboardExpand all lines: tests/jest-puppeteer.config.js
+11-6Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// get environment variable
2-
const CI = !!process.env.CI;
3-
4-
const baseOptions = {
1+
const defaultOptions = {
2+
launch: {
3+
headless: true,
4+
},
55
server: {
66
command: 'npm run start',
77
port: 6969,
@@ -22,7 +22,12 @@ const ciPipelineOptions = {
2222
'--disable-gpu'
2323
]
2424
},
25-
...baseOptions
25+
server: {
26+
command: 'npm run start',
27+
port: 6969,
28+
launchTimeout: 25000
29+
},
30+
browserContext: 'incognito'
2631
}
2732

28-
module.exports = CI ? ciPipelineOptions : baseOptions;
33+
module.exports = process.env.CI ? ciPipelineOptions : defaultOptions;
Collapse file

‎tests/src/DynamicHead.njs‎

Copy file name to clipboardExpand all lines: tests/src/DynamicHead.njs
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Nullstack from 'nullstack';
33
class DynamicHead extends Nullstack {
44

55
count = 0
6+
negativeCount = 0
67

78
renderHead() {
89
const innerComponent = `[data-inner-component] { color: blue }`
@@ -30,21 +31,21 @@ class DynamicHead extends Nullstack {
3031
</>
3132
<Head />
3233
</head>
33-
{this.count % 2 === 0 &&
34+
{this.count === 1 &&
3435
<head>
3536
<style html={conditionalHead} data-conditional-head />
3637
</head>
3738
}
3839
<head>
39-
{Array(this.count + 1).fill(<style html={dynamicLength} data-dynamic-length={this.count} />)}
40+
{Array(this.count + 1 - this.negativeCount).fill(<style html={dynamicLength} data-dynamic-length={this.count} data-negative-count={this.negativeCount === 1} />)}
4041
</head>
4142
{this.count % 2 === 0 ?
4243
<head>
4344
<meta name="test" content="nullstack" data-ternary-head />
4445
</head> : <span data-ternary-span> not head </span>
4546
}
4647
<button onclick={{ count: this.count + 1 }} data-increment> inc {this.count} </button>
47-
<button onclick={{ count: this.count - 1 }} data-decrement> dec {this.count} </button>
48+
<button onclick={{ negativeCount: this.negativeCount + 1 }} data-decrement> dec {this.count} </button>
4849
<span data-red-blue> data-red-blue </span>
4950
<span data-prerender-conditional> data-prerender-conditional </span>
5051
<span data-rerender-conditional> data-rerender-conditional </span>
Collapse file

‎tests/src/DynamicHead.test.js‎

Copy file name to clipboardExpand all lines: tests/src/DynamicHead.test.js
+15-3Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,21 @@ describe('DynamicHead', () => {
7878
await page.waitForSelector(`[data-dynamic-length="${i}"]`);
7979
}
8080
await page.click('[data-decrement]');
81-
await page.waitForSelector('[data-dynamic-length="2"]');
82-
await page.waitForTimeout(500)
83-
const elements = await page.$$('[data-dynamic-length]');
81+
await page.waitForSelector('[data-negative-count]');
82+
const elements = await page.$$('[data-negative-count]');
8483
expect(elements.length).toEqual(2);
8584
});
85+
86+
test('dynamic head elements can update attributes', async () => {
87+
for (let i = 1; i < 3; i++) {
88+
await page.click('[data-increment]');
89+
await page.waitForSelector(`[data-dynamic-length="${i}"]`);
90+
}
91+
await page.click('[data-decrement]');
92+
await page.waitForSelector('[data-negative-count]');
93+
await page.click('[data-decrement]');
94+
await page.waitForSelector('[data-dynamic-length]:not([data-negative-count])');
95+
const element = await page.$('[data-dynamic-length]:not([data-negative-count])');
96+
expect(element).toBeTruthy();
97+
});
8698
});
Collapse file

‎tests/src/StatefulComponent.njs‎

Copy file name to clipboardExpand all lines: tests/src/StatefulComponent.njs
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class StatefulComponent extends Nullstack {
4949
</>
5050
<button onclick={{ visible: !this.visible }} data-toggle> Toggle </button>
5151
{this.visible && <button onclick={undefined} data-undefined-event> button </button>}
52+
<textarea> {this.count} {this.count} </textarea>
5253
</form>
5354
)
5455
}
Collapse file

‎tests/src/StatefulComponent.test.js‎

Copy file name to clipboardExpand all lines: tests/src/StatefulComponent.test.js
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,16 @@ describe('StatefulComponent', () => {
6464
expect(hasConsoleError).toBeFalsy();
6565
});
6666

67+
test('textareas with multiple nodes become a single node', async () => {
68+
const text = await page.$eval('textarea', (e) => e.value);
69+
expect(text).toMatch(' 1 1 ');
70+
});
71+
72+
test('textareas with multiple nodes can be updated', async () => {
73+
await page.click('.increment-by-one');
74+
await page.waitForSelector('[data-count="2"]');
75+
const text = await page.$eval('textarea', (e) => e.value);
76+
expect(text).toMatch(' 2 2 ');
77+
});
78+
6779
});

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.