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

Test breaking changes byte offset for compat #4460

Closed
wants to merge 3 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
30 changes: 4 additions & 26 deletions compat/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,9 @@ import { memo } from './memo';
import { forwardRef } from './forwardRef';
import { Children } from './Children';
import { Suspense, lazy } from './suspense';
import { SuspenseList } from './suspense-list';
import { createPortal } from './portals';
import { is } from './util';
import {
hydrate,
render,
REACT_ELEMENT_TYPE,
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
} from './render';
import { hydrate, render, REACT_ELEMENT_TYPE } from './render';

const version = '17.0.2'; // trick libraries to think we are react

Expand Down Expand Up @@ -95,6 +89,7 @@ function cloneElement(element) {
* @param {import('./internal').PreactElement} container
* @returns {boolean}
*/
// TODO: replaced with root.unmount()
function unmountComponentAtNode(container) {
if (container._children) {
preactRender(null, container);
Expand All @@ -116,16 +111,6 @@ function findDOMNode(component) {
);
}

/**
* Deprecated way to control batched rendering inside the reconciler, but we
* already schedule in batches inside our rendering code
* @template Arg
* @param {(arg: Arg) => void} callback function that triggers the updated
* @param {Arg} [arg] Optional argument that can be passed to the callback
*/
// eslint-disable-next-line camelcase
const unstable_batchedUpdates = (callback, arg) => callback(arg);

/**
* In React, `flushSync` flushes the entire tree and forces a rerender. It's
* implmented here as a no-op.
Expand Down Expand Up @@ -237,13 +222,9 @@ export {
memo,
forwardRef,
flushSync,
// eslint-disable-next-line camelcase
unstable_batchedUpdates,
StrictMode,
Suspense,
SuspenseList,
lazy,
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
lazy
};

// React copies the named exports to the default one.
Expand Down Expand Up @@ -286,10 +267,7 @@ export default {
memo,
forwardRef,
flushSync,
unstable_batchedUpdates,
StrictMode,
Suspense,
SuspenseList,
lazy,
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
lazy
};
73 changes: 1 addition & 72 deletions compat/src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,42 +39,11 @@ const IS_DOM = typeof document !== 'undefined';
// Input types for which onchange should not be converted to oninput.
// type="file|checkbox|radio", plus "range" in IE11.
// (IE11 doesn't support Symbol, which we use here to turn `rad` into `ra` which matches "range")
const onChangeInputType = type =>
(typeof Symbol != 'undefined' && typeof Symbol() == 'symbol'
? /fil|che|rad/
: /fil|che|ra/
).test(type);
const onChangeInputType = type => /fil|che|ra/.test(type);

// Some libraries like `react-virtualized` explicitly check for this.
Component.prototype.isReactComponent = {};

// `UNSAFE_*` lifecycle hooks
// Preact only ever invokes the unprefixed methods.
// Here we provide a base "fallback" implementation that calls any defined UNSAFE_ prefixed method.
// - If a component defines its own `componentDidMount()` (including via defineProperty), use that.
// - If a component defines `UNSAFE_componentDidMount()`, `componentDidMount` is the alias getter/setter.
// - If anything assigns to an `UNSAFE_*` property, the assignment is forwarded to the unprefixed property.
// See https://github.com/preactjs/preact/issues/1941
[
'componentWillMount',
'componentWillReceiveProps',
'componentWillUpdate'
].forEach(key => {
Object.defineProperty(Component.prototype, key, {
configurable: true,
get() {
return this['UNSAFE_' + key];
},
set(v) {
Object.defineProperty(this, key, {
configurable: true,
writable: true,
value: v
});
}
});
});

/**
* Proxy render() since React returns a Component reference.
* @param {import('./internal').VNode} vnode VNode tree to render
Expand Down Expand Up @@ -250,16 +219,6 @@ options.vnode = vnode => {
if (oldVNodeHook) oldVNodeHook(vnode);
};

// Only needed for react-relay
let currentComponent;
const oldBeforeRender = options._render;
options._render = function (vnode) {
if (oldBeforeRender) {
oldBeforeRender(vnode);
}
currentComponent = vnode._component;
};

const oldDiffed = options.diffed;
/** @type {(vnode: import('./internal').VNode) => void} */
options.diffed = function (vnode) {
Expand All @@ -278,34 +237,4 @@ options.diffed = function (vnode) {
) {
dom.value = props.value == null ? '' : props.value;
}

currentComponent = null;
};

// This is a very very private internal function for React it
// is used to sort-of do runtime dependency injection.
export const __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = {
ReactCurrentDispatcher: {
current: {
readContext(context) {
return currentComponent._globalContext[context._id].props.value;
},
useCallback,
useContext,
useDebugValue,
useDeferredValue,
useEffect,
useId,
useImperativeHandle,
useInsertionEffect,
useLayoutEffect,
useMemo,
// useMutableSource, // experimental-only and replaced by uSES, likely not worth supporting
useReducer,
useRef,
useState,
useSyncExternalStore,
useTransition
}
}
};
14 changes: 0 additions & 14 deletions compat/src/suspense-list.d.ts

This file was deleted.

127 changes: 0 additions & 127 deletions compat/src/suspense-list.js

This file was deleted.

Loading