Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport 10.17 #4352

Closed
wants to merge 4 commits into from
Closed
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 .github/workflows/pr-reporter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ jobs:
uses: andrewiggins/tachometer-reporter-action@v2
with:
path: results/*.json
base-bench-name: preact-master
base-bench-name: preact-main
pr-bench-name: preact-local
summarize: 'duration, usedJSHeapSize'
2 changes: 1 addition & 1 deletion benches/scripts/bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const defaultBenchOptions = {
// GitHub Action minutes
timeout: 1,
'window-size': '1024,768',
framework: IS_CI ? ['preact-master', 'preact-local'] : null,
framework: IS_CI ? ['preact-main', 'preact-local'] : null,
memory: true,
trace: false
};
Expand Down
5 changes: 2 additions & 3 deletions benches/scripts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ export const frameworks = [
}
},
{
label: 'preact-master',
label: 'preact-main',
dependencies: {
framework:
'file:' + repoRoot('benches/proxy-packages/preact-master-proxy')
framework: 'file:' + repoRoot('benches/proxy-packages/preact-main-proxy')
},
async isValid() {
try {
Expand Down
6 changes: 3 additions & 3 deletions benches/scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ prog
.example('bench text*')
.example('bench *.html')
.example('bench all')
.example('bench many* -f preact-local -f preact-master')
.example('bench many* -f preact-local -f preact-main')
.option(
'--browser, -b',
'Which browsers to launch in automatic mode, comma-delimited (chrome, chrome-headless, firefox, firefox-headless, safari, edge, ie)',
Expand Down Expand Up @@ -77,7 +77,7 @@ prog
// Tests:
// - (no args)
// - many*
// - many* -f preact-local -f preact-master
// - many* -f preact-local -f preact-main
prog
.command('deopts [benchmark]')
.describe(
Expand All @@ -86,7 +86,7 @@ prog
.example('deopts many_updates.html')
.example('deopts many*')
.example('deopts many* -f preact-local')
.example('deopts many* -f preact-local -f preact-master')
.example('deopts many* -f preact-local -f preact-main')
.option(
'--framework, -f',
'The framework to run the benchmark with.',
Expand Down
6 changes: 3 additions & 3 deletions src/jsx.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1075,9 +1075,9 @@ export namespace JSXInternal {
export type TargetedPictureInPictureEvent<Target extends EventTarget> =
TargetedEvent<Target, PictureInPictureEvent>;

export interface EventHandler<E extends TargetedEvent> {
(this: void, event: E): void;
}
export type EventHandler<E extends TargetedEvent> = {
bivarianceHack(event: E): void;
}['bivarianceHack'];

export type AnimationEventHandler<Target extends EventTarget> = EventHandler<
TargetedAnimationEvent<Target>
Expand Down
66 changes: 66 additions & 0 deletions test/browser/keys.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -754,4 +754,70 @@
done();
});
});

// TODO: #4088
it.skip('should handle full reorders', () => {
const keys = {
Apple: `Apple_1`,
Orange: `Orange_1`,
Banana: `Banana_1`,
Grape: `Grape_1`,
Kiwi: `Kiwi_1`,
Cherry: `Cherry_1`
};

let sort;

class App extends Component {
order;

state = { items: ['Apple', 'Grape', 'Cherry', 'Orange', 'Banana'] };

sort() {
this.order = this.order === 'ASC' ? 'DESC' : 'ASC';
const items = [...this.state.items].sort((a, b) =>
this.order === 'ASC' ? a.localeCompare(b) : b.localeCompare(a)
);
this.setState({ items });
}

render(_, { items }) {
sort = this.sort.bind(this);
return (
<div>
{items.map(item => (
<div key={keys[item]}>{item}</div>
))}
</div>
);
}
}

const expected = values => {
return values.map(key => `<div>${key}</div>`).join('');
};

render(<App />, scratch);
expect(scratch.innerHTML).to.eq(
`<div>${expected(['Apple', 'Grape', 'Cherry', 'Orange', 'Banana'])}</div>`
);

console.log('--------');

Check warning on line 805 in test/browser/keys.test.js

View workflow job for this annotation

GitHub Actions / Build & Test

Unexpected console statement
let sorted = ['Apple', 'Grape', 'Cherry', 'Orange', 'Banana'].sort((a, b) =>
a.localeCompare(b)
);
sort();
rerender();

expect(scratch.innerHTML).to.eq(`<div>${expected(sorted)}</div>`);

console.log('--------');

Check warning on line 814 in test/browser/keys.test.js

View workflow job for this annotation

GitHub Actions / Build & Test

Unexpected console statement
sorted = ['Apple', 'Grape', 'Cherry', 'Orange', 'Banana'].sort((a, b) =>
b.localeCompare(a)
);
sort();
rerender();

expect(scratch.innerHTML).to.eq(`<div>${expected(sorted)}</div>`);
});
});
114 changes: 113 additions & 1 deletion test/browser/placeholders.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createElement, Component, render, createRef } from 'preact';
import { createElement, Component, render, createRef, Fragment } from 'preact';
import { setupRerender } from 'preact/test-utils';
import { setupScratch, teardown } from '../_util/helpers';
import { logCall, clearLog, getLog } from '../_util/logCall';
Expand Down Expand Up @@ -304,4 +304,116 @@ describe('null placeholders', () => {
expect(scratch.innerHTML).to.equal(div([div('false'), div('the middle')]));
expect(getLog()).to.deep.equal(['#text.remove()', '#text.remove()']);
});

it('when set through the children prop (#4074)', () => {
/** @type {(state: { value: boolean }) => void} */
let setState;
const Iframe = () => {
// Using a div here to make debugging tests in devtools a little less
// noisy. The dom ops still assert that the iframe isn't moved.
//
// return <iframe src="https://codesandbox.io/s/runtime-silence-no4zx" />;
return <div>Iframe</div>;
};

const Test2 = () => <div>Test2</div>;
const Test3 = () => <div>Test3</div>;

class App extends Component {
constructor(props) {
super(props);
this.state = { value: true };
setState = this.setState.bind(this);
}

render(props, state) {
return (
<div>
<Test2 />
{state.value && <Test3 />}
{props.children}
</div>
);
}
}

render(
<App>
<Iframe />
</App>,
scratch
);

expect(scratch.innerHTML).to.equal(
'<div><div>Test2</div><div>Test3</div><div>Iframe</div></div>'
);
clearLog();
setState({ value: false });
rerender();

expect(scratch.innerHTML).to.equal(
'<div><div>Test2</div><div>Iframe</div></div>'
);
expect(getLog()).to.deep.equal(['<div>Test3.remove()']);
});

it('when set through the children prop when removing a Fragment with multiple DOM children (#4074)', () => {
/** @type {(state: { value: boolean }) => void} */
let setState;
const Iframe = () => {
// Using a div here to make debugging tests in devtools a little less
// noisy. The dom ops still assert that the iframe isn't moved.
//
// return <iframe src="https://codesandbox.io/s/runtime-silence-no4zx" />;
return <div>Iframe</div>;
};

const Test2 = () => <div>Test2</div>;
const Test34 = () => (
<Fragment>
<div>Test3</div>
<div>Test4</div>
</Fragment>
);

class App extends Component {
constructor(props) {
super(props);
this.state = { value: true };
setState = this.setState.bind(this);
}

render(props, state) {
return (
<div>
<Test2 />
{state.value && <Test34 />}
{props.children}
</div>
);
}
}

render(
<App>
<Iframe />
</App>,
scratch
);

expect(scratch.innerHTML).to.equal(
'<div><div>Test2</div><div>Test3</div><div>Test4</div><div>Iframe</div></div>'
);
clearLog();
setState({ value: false });
rerender();

expect(scratch.innerHTML).to.equal(
'<div><div>Test2</div><div>Iframe</div></div>'
);
expect(getLog()).to.deep.equal([
'<div>Test3.remove()',
'<div>Test4.remove()'
]);
});
});
13 changes: 13 additions & 0 deletions test/ts/Component-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,16 @@ describe('Component', () => {
});
});
});

class Button extends Component {
handleClick(this: HTMLButtonElement, event: MouseEvent) {
event.preventDefault();
if (event.target instanceof HTMLElement) {
console.log(event.target.localName);
}
}

render() {
return <button onClick={this.handleClick}>{this.props.children}</button>;
}
}
Loading