Skip to content

Commit 94bfe9d

Browse files
Merge branch 'main' into main
2 parents 1584d4c + e174713 commit 94bfe9d

12 files changed

Lines changed: 37 additions & 40 deletions

File tree

.github/workflows/benchmarks.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ jobs:
2626
timeout-minutes: 5
2727
steps:
2828
- name: Download locally built preact package
29-
uses: actions/download-artifact@v4
29+
uses: actions/download-artifact@v3
3030
with:
3131
name: npm-package
3232
- run: mv preact.tgz preact-local.tgz
3333
- name: Upload locally built preact package
34-
uses: actions/upload-artifact@v4
34+
uses: actions/upload-artifact@v3
3535
with:
3636
name: bench-environment
3737
path: preact-local.tgz

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
npm pack --ignore-scripts
5757
mv preact-*.tgz preact.tgz
5858
- name: Upload npm package
59-
uses: actions/upload-artifact@v4
59+
uses: actions/upload-artifact@v3
6060
with:
6161
name: ${{ inputs.artifact_name || 'npm-package' }}
6262
path: preact.tgz

compat/test/browser/useSyncExternalStore.test.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,10 @@ describe('useSyncExternalStore', () => {
658658
await act(() => {
659659
store.set(1);
660660
});
661-
assertLog([1, 1, 'Reset back to 0', 0, 0]);
661+
// Preact logs differ from React here cuz of how we do rerendering. We
662+
// rerender subtrees and then commit effects so Child2 never sees the
663+
// update to 1 cuz Child1 rerenders and runs its layout effects first.
664+
assertLog([1, /*1,*/ 'Reset back to 0', 0, 0]);
662665
expect(container.textContent).to.equal('00');
663666
});
664667

devtools/src/devtools.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { options, Fragment, Component } from 'preact';
22

33
export function initDevTools() {
44
if (typeof window != 'undefined' && window.__PREACT_DEVTOOLS__) {
5-
window.__PREACT_DEVTOOLS__.attachPreact('10.19.6', options, {
5+
window.__PREACT_DEVTOOLS__.attachPreact('10.19.7', options, {
66
Fragment,
77
Component
88
});

hooks/src/index.d.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,24 @@ import { ErrorInfo, PreactContext, Ref as PreactRef } from '../..';
22

33
type Inputs = ReadonlyArray<unknown>;
44

5-
export type StateUpdater<S> = (value: S | ((prevState: S) => S)) => void;
5+
export type Dispatch<A> = (value: A) => void;
6+
export type StateUpdater<S> = S | ((prevState: S) => S);
7+
68
/**
79
* Returns a stateful value, and a function to update it.
810
* @param initialState The initial value (or a function that returns the initial value)
911
*/
10-
export function useState<S>(initialState: S | (() => S)): [S, StateUpdater<S>];
12+
export function useState<S>(
13+
initialState: S | (() => S)
14+
): [S, Dispatch<StateUpdater<S>>];
1115

1216
export function useState<S = undefined>(): [
1317
S | undefined,
14-
StateUpdater<S | undefined>
18+
Dispatch<StateUpdater<S | undefined>>
1519
];
1620

1721
export type Reducer<S, A> = (prevState: S, action: A) => S;
18-
export type Dispatch<A> = (action: A) => void;
22+
1923
/**
2024
* An alternative to `useState`.
2125
*

hooks/src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ function getHookState(index, type) {
167167

168168
/**
169169
* @template {unknown} S
170-
* @param {import('./index').StateUpdater<S>} [initialState]
170+
* @param {import('./index').Dispatch<import('./index').StateUpdater<S>>} [initialState]
171171
* @returns {[S, (state: S) => void]}
172172
*/
173173
export function useState(initialState) {
@@ -179,7 +179,7 @@ export function useState(initialState) {
179179
* @template {unknown} S
180180
* @template {unknown} A
181181
* @param {import('./index').Reducer<S, A>} reducer
182-
* @param {import('./index').StateUpdater<S>} initialState
182+
* @param {import('./index').Dispatch<import('./index').StateUpdater<S>>} initialState
183183
* @param {(initialState: any) => void} [init]
184184
* @returns {[ S, (state: S) => void ]}
185185
*/

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "preact",
33
"amdName": "preact",
4-
"version": "10.19.6",
4+
"version": "10.19.7",
55
"private": false,
66
"description": "Fast 3kb React-compatible Virtual DOM library.",
77
"main": "dist/preact.js",

src/component.js

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { assign } from './util';
22
import { diff, commitRoot } from './diff/index';
33
import options from './options';
44
import { Fragment } from './create-element';
5-
import { EMPTY_ARR, MODE_HYDRATE } from './constants';
5+
import { MODE_HYDRATE } from './constants';
66

77
/**
88
* Base Component class. Provides `setState()` and `forceUpdate()`, which
@@ -120,10 +120,12 @@ export function getDomSibling(vnode, childIndex) {
120120
* Trigger in-place re-rendering of a component.
121121
* @param {Component} component The component to rerender
122122
*/
123-
function renderComponent(component, commitQueue, refQueue) {
123+
function renderComponent(component) {
124124
let oldVNode = component._vnode,
125125
oldDom = oldVNode._dom,
126-
parentDom = component._parentDom;
126+
parentDom = component._parentDom,
127+
commitQueue = [],
128+
refQueue = [];
127129

128130
if (parentDom) {
129131
const newVNode = assign({}, oldVNode);
@@ -145,14 +147,11 @@ function renderComponent(component, commitQueue, refQueue) {
145147

146148
newVNode._original = oldVNode._original;
147149
newVNode._parent._children[newVNode._index] = newVNode;
148-
149-
newVNode._nextDom = undefined;
150+
commitRoot(commitQueue, newVNode, refQueue);
150151

151152
if (newVNode._dom != oldDom) {
152153
updateParentDomPointers(newVNode);
153154
}
154-
155-
return newVNode;
156155
}
157156
}
158157

@@ -222,33 +221,21 @@ const depthSort = (a, b) => a._vnode._depth - b._vnode._depth;
222221
/** Flush the render queue by rerendering all queued components */
223222
function process() {
224223
let c;
225-
let commitQueue = [];
226-
let refQueue = [];
227-
let root;
228224
rerenderQueue.sort(depthSort);
229225
// Don't update `renderCount` yet. Keep its value non-zero to prevent unnecessary
230226
// process() calls from getting scheduled while `queue` is still being consumed.
231227
while ((c = rerenderQueue.shift())) {
232228
if (c._dirty) {
233229
let renderQueueLength = rerenderQueue.length;
234-
root = renderComponent(c, commitQueue, refQueue) || root;
235-
// If this WAS the last component in the queue, run commit callbacks *before* we exit the tight loop.
236-
// This is required in order for `componentDidMount(){this.setState()}` to be batched into one flush.
237-
// Otherwise, also run commit callbacks if the render queue was mutated.
238-
if (renderQueueLength === 0 || rerenderQueue.length > renderQueueLength) {
239-
commitRoot(commitQueue, root, refQueue);
240-
refQueue.length = commitQueue.length = 0;
241-
root = undefined;
230+
renderComponent(c);
231+
if (rerenderQueue.length > renderQueueLength) {
242232
// When i.e. rerendering a provider additional new items can be injected, we want to
243233
// keep the order from top to bottom with those new items so we can handle them in a
244234
// single pass
245235
rerenderQueue.sort(depthSort);
246-
} else if (root) {
247-
if (options._commit) options._commit(root, EMPTY_ARR);
248236
}
249237
}
250238
}
251-
if (root) commitRoot(commitQueue, root, refQueue);
252239
process._rerenderCount = 0;
253240
}
254241

src/diff/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ export function diff(
311311
* @param {VNode} root
312312
*/
313313
export function commitRoot(commitQueue, root, refQueue) {
314+
root._nextDom = undefined;
315+
314316
for (let i = 0; i < refQueue.length; i++) {
315317
applyRef(refQueue[i], refQueue[++i], refQueue[++i]);
316318
}

0 commit comments

Comments
 (0)