Skip to content

Commit

Permalink
Merge branch 'main' into test-perf-of-less-args
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed May 21, 2024
2 parents db405cc + 85bed33 commit 79c9445
Show file tree
Hide file tree
Showing 29 changed files with 1,065 additions and 2,752 deletions.
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test/fixtures
test/ts/
*.ts
dist
benchmarks
3 changes: 3 additions & 0 deletions .github/workflows/size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ jobs:
- uses: preactjs/compressed-size-action@v2
with:
repo-token: '${{ secrets.GITHUB_TOKEN }}'
# Our `prepare` script already builds the app post-install,
# building it again would be redundant
build-script: 'npm run --if-present noop'
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npx lint-staged
4 changes: 2 additions & 2 deletions benches/scripts/analyze.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ async function getStatsFromLogs(version, logPaths, getThreadId, trackEventsIn) {
unit: key.startsWith('Count')
? ''
: key.includes('usedHeapSize')
? 'MB'
: null
? 'MB'
: null
},
browser: {
name: 'chrome'
Expand Down
56 changes: 56 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"formatter": {
"enabled": true,
"formatWithErrors": false,
"indentStyle": "tab",
"indentWidth": 2,
"lineEnding": "lf",
"lineWidth": 80,
"attributePosition": "auto",
"ignore": [
"**/.DS_Store",
"**/node_modules",
"**/npm-debug.log",
"**/dist",
"*/package-lock.json",
"**/yarn.lock",
"**/.vscode",
"**/.idea",
"test/ts/**/*.js",
"**/coverage",
"**/*.sw[op]",
"**/*.log",
"**/package/",
"**/preact-*.tgz",
"**/preact.tgz",
"benches/dist/",
"benches/results/",
"benches/logs/",
"benches/logs-saved/",
"benches/node_modules/",
"benches/proxy-packages/*/package-lock.json",
"**/package-lock.json"
]
},
"organizeImports": { "enabled": true },
"linter": { "enabled": true, "rules": { "recommended": true } },
"javascript": {
"formatter": {
"jsxQuoteStyle": "double",
"quoteProperties": "asNeeded",
"trailingComma": "none",
"semicolons": "always",
"arrowParentheses": "asNeeded",
"bracketSpacing": true,
"bracketSameLine": false,
"quoteStyle": "single",
"attributePosition": "auto"
}
},
"overrides": [
{
"include": ["*.json", ".*rc", "*.yml"],
"formatter": { "indentWidth": 2, "indentStyle": "space" }
}
]
}
6 changes: 4 additions & 2 deletions compat/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ const { render, hydrate, unmountComponentAtNode } = require('preact/compat');

function createRoot(container) {
return {
render(children) {
// eslint-disable-next-line
render: function (children) {
render(children, container);
},
unmount() {
// eslint-disable-next-line
unmount: function () {
unmountComponentAtNode(container);
}
};
Expand Down
6 changes: 4 additions & 2 deletions compat/client.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { render, hydrate, unmountComponentAtNode } from 'preact/compat';

export function createRoot(container) {
return {
render(children) {
// eslint-disable-next-line
render: function (children) {
render(children, container);
},
unmount() {
// eslint-disable-next-line
unmount: function () {
unmountComponentAtNode(container);
}
};
Expand Down
4 changes: 3 additions & 1 deletion compat/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ declare namespace React {

export type ComponentPropsWithRef<
C extends ComponentType<any> | keyof JSXInternal.IntrinsicElements
> = C extends new (props: infer P) => Component<any, any>
> = C extends new (
props: infer P
) => Component<any, any>
? PropsWithoutRef<P> & RefAttributes<InstanceType<C>>
: ComponentProps<C>;

Expand Down
4 changes: 2 additions & 2 deletions compat/test/browser/testUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ export function getSymbol(name, fallback) {
// eslint-disable-next-line
if (
Function.prototype.toString
.call(eval('Symbol.for'))
.call((0, eval)('Symbol.for'))
.match(/\[native code\]/)
) {
// Concatenate these string literals to prevent the test
// harness and/or Babel from modifying the symbol value.
// eslint-disable-next-line
out = eval('Sym' + 'bol.for("' + name + '")');
out = (0, eval)('Sym' + 'bol.for("' + name + '")');
}
} catch (e) {}

Expand Down
29 changes: 24 additions & 5 deletions debug/src/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function initDebug() {
useEffect: new WeakMap(),
useLayoutEffect: new WeakMap(),
lazyPropTypes: new WeakMap()
};
};
const deprecations = [];

options._catchError = (error, vnode, oldVNode, errorInfo) => {
Expand Down Expand Up @@ -353,7 +353,17 @@ export function initDebug() {
});
}

if (typeof type === 'string' && (isTableElement(type) || type === 'p')) {
if (vnode._component === currentComponent) {
renderCount = 0;
}

if (
typeof type === 'string' &&
(isTableElement(type) ||
type === 'p' ||
type === 'a' ||
type === 'button')
) {
// Avoid false positives when Preact only partially rendered the
// HTML tree. Whilst we attempt to include the outer DOM in our
// validation, this wouldn't work on the server for
Expand Down Expand Up @@ -387,11 +397,10 @@ export function initDebug() {
type === 'tr' &&
domParentName !== 'thead' &&
domParentName !== 'tfoot' &&
domParentName !== 'tbody' &&
domParentName !== 'table'
domParentName !== 'tbody'
) {
console.error(
'Improper nesting of table. Your <tr> should have a <thead/tbody/tfoot/table> parent.' +
'Improper nesting of table. Your <tr> should have a <thead/tbody/tfoot> parent.' +
serializeVNode(vnode) +
`\n\n${getOwnerStack(vnode)}`
);
Expand Down Expand Up @@ -421,6 +430,16 @@ export function initDebug() {
`\n\n${getOwnerStack(vnode)}`
);
}
} else if (type === 'a' || type === 'button') {
if (getDomChildren(vnode).indexOf(type) !== -1) {
console.error(
`Improper nesting of interactive content. Your <${type}>` +
` should not have other ${type === 'a' ? 'anchor' : 'button'}` +
' tags as child-elements.' +
serializeVNode(vnode) +
`\n\n${getOwnerStack(vnode)}`
);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion debug/test/browser/debug-compat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('debug compat', () => {

afterEach(() => {
/** @type {*} */
(console.error).restore();
console.error.restore();
console.warn.restore();
teardown(scratch);

Expand Down

0 comments on commit 79c9445

Please sign in to comment.