Skip to content
Merged
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
1 change: 1 addition & 0 deletions compat/mangle.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"properties": {
"regex": "^_[^_]",
"reserved": [
"__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED",
"__REACT_DEVTOOLS_GLOBAL_HOOK__",
"__PREACT_DEVTOOLS__",
"_renderers",
Expand Down
13 changes: 10 additions & 3 deletions compat/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ import { Children } from './Children';
import { Suspense, lazy } from './suspense';
import { SuspenseList } from './suspense-list';
import { createPortal } from './portals';
import { hydrate, render, REACT_ELEMENT_TYPE } from './render';
import {
hydrate,
render,
REACT_ELEMENT_TYPE,
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
} from './render';

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

Expand Down Expand Up @@ -126,7 +131,8 @@ export {
StrictMode,
Suspense,
SuspenseList,
lazy
lazy,
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
};

// React copies the named exports to the default one.
Expand Down Expand Up @@ -163,5 +169,6 @@ export default {
StrictMode,
Suspense,
SuspenseList,
lazy
lazy,
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
};
24 changes: 24 additions & 0 deletions compat/src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,27 @@ 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;
};

// This is a very very private internal function for React it
// is used to sort-of do runtime dependency injection. So far
// only `react-relay` makes use of it. It uses it to read the
// context value.
export const __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = {
ReactCurrentDispatcher: {
current: {
readContext(context) {
return currentComponent._globalContext[context._id].props.value;
}
}
}
};
30 changes: 29 additions & 1 deletion compat/test/browser/render.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React, {
createElement,
render,
Component,
hydrate
hydrate,
createContext
} from 'preact/compat';
import { setupRerender, act } from 'preact/test-utils';
import {
Expand Down Expand Up @@ -312,4 +313,31 @@ describe('compat render', () => {
expect(mountSpy).to.be.calledOnce;
expect(updateSpy).to.not.be.calledOnce;
});

it("should support react-relay's usage of __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED", () => {
const Ctx = createContext('foo');

// Simplified version of: https://github.com/facebook/relay/blob/fba79309977bf6b356ee77a5421ca5e6f306223b/packages/react-relay/readContext.js#L17-L28
function readContext(Context) {
const {
ReactCurrentDispatcher
} = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
const dispatcher = ReactCurrentDispatcher.current;
return dispatcher.readContext(Context);
}

function Foo() {
const value = readContext(Ctx);
return <div>{value}</div>;
}

React.render(
<Ctx.Provider value="foo">
<Foo />
</Ctx.Provider>,
scratch
);

expect(scratch.textContent).to.equal('foo');
});
});
1 change: 1 addition & 0 deletions debug/mangle.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"properties": {
"regex": "^_[^_]",
"reserved": [
"__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED",
"__REACT_DEVTOOLS_GLOBAL_HOOK__",
"__PREACT_DEVTOOLS__",
"_renderers",
Expand Down
1 change: 1 addition & 0 deletions devtools/mangle.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"properties": {
"regex": "^_[^_]",
"reserved": [
"__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED",
"__REACT_DEVTOOLS_GLOBAL_HOOK__",
"__PREACT_DEVTOOLS__",
"_renderers",
Expand Down
1 change: 1 addition & 0 deletions hooks/mangle.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"properties": {
"regex": "^_[^_]",
"reserved": [
"__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED",
"__REACT_DEVTOOLS_GLOBAL_HOOK__",
"__PREACT_DEVTOOLS__",
"_renderers",
Expand Down
1 change: 1 addition & 0 deletions mangle.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"properties": {
"regex": "^_[^_]",
"reserved": [
"__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED",
"__REACT_DEVTOOLS_GLOBAL_HOOK__",
"__PREACT_DEVTOOLS__",
"_renderers",
Expand Down