Skip to content

Commit

Permalink
Merge branch 'main' into jestbump
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Feb 9, 2023
2 parents 9a949a8 + 28fcae0 commit 3f8db9b
Show file tree
Hide file tree
Showing 76 changed files with 3,212 additions and 1,621 deletions.
52 changes: 51 additions & 1 deletion fixtures/attribute-behavior/AttributeTableSnapshot.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## `about` (on `<div>` inside `<div>`)
## `about` (on `<div>` inside `<div>`)
| Test Case | Flags | Result |
| --- | --- | --- |
| `about=(string)`| (changed)| `"a string"` |
Expand Down Expand Up @@ -11373,6 +11373,56 @@
| `transform=(null)`| (initial)| `[]` |
| `transform=(undefined)`| (initial)| `[]` |

## `transform-origin` (on `<svg>` inside `<div>`)
| Test Case | Flags | Result |
| --- | --- | --- |
| `transform-origin=(string)`| (changed, warning)| `"a string"` |
| `transform-origin=(empty string)`| (changed, warning)| `<empty string>` |
| `transform-origin=(array with string)`| (changed, warning)| `"string"` |
| `transform-origin=(empty array)`| (changed, warning)| `<empty string>` |
| `transform-origin=(object)`| (changed, warning)| `"result of toString()"` |
| `transform-origin=(numeric string)`| (changed, warning)| `"42"` |
| `transform-origin=(-1)`| (changed, warning)| `"-1"` |
| `transform-origin=(0)`| (changed, warning)| `"0"` |
| `transform-origin=(integer)`| (changed, warning)| `"1"` |
| `transform-origin=(NaN)`| (changed, warning)| `"NaN"` |
| `transform-origin=(float)`| (changed, warning)| `"99.99"` |
| `transform-origin=(true)`| (initial, warning)| `<null>` |
| `transform-origin=(false)`| (initial, warning)| `<null>` |
| `transform-origin=(string 'true')`| (changed, warning)| `"true"` |
| `transform-origin=(string 'false')`| (changed, warning)| `"false"` |
| `transform-origin=(string 'on')`| (changed, warning)| `"on"` |
| `transform-origin=(string 'off')`| (changed, warning)| `"off"` |
| `transform-origin=(symbol)`| (initial, warning)| `<null>` |
| `transform-origin=(function)`| (initial, warning)| `<null>` |
| `transform-origin=(null)`| (initial, warning)| `<null>` |
| `transform-origin=(undefined)`| (initial, warning)| `<null>` |

## `transformOrigin` (on `<svg>` inside `<div>`)
| Test Case | Flags | Result |
| --- | --- | --- |
| `transformOrigin=(string)`| (changed)| `"a string"` |
| `transformOrigin=(empty string)`| (changed)| `<empty string>` |
| `transformOrigin=(array with string)`| (changed)| `"string"` |
| `transformOrigin=(empty array)`| (changed)| `<empty string>` |
| `transformOrigin=(object)`| (changed)| `"result of toString()"` |
| `transformOrigin=(numeric string)`| (changed)| `"42"` |
| `transformOrigin=(-1)`| (changed)| `"-1"` |
| `transformOrigin=(0)`| (changed)| `"0"` |
| `transformOrigin=(integer)`| (changed)| `"1"` |
| `transformOrigin=(NaN)`| (changed, warning)| `"NaN"` |
| `transformOrigin=(float)`| (changed)| `"99.99"` |
| `transformOrigin=(true)`| (initial, warning)| `<null>` |
| `transformOrigin=(false)`| (initial, warning)| `<null>` |
| `transformOrigin=(string 'true')`| (changed)| `"true"` |
| `transformOrigin=(string 'false')`| (changed)| `"false"` |
| `transformOrigin=(string 'on')`| (changed)| `"on"` |
| `transformOrigin=(string 'off')`| (changed)| `"off"` |
| `transformOrigin=(symbol)`| (initial, warning)| `<null>` |
| `transformOrigin=(function)`| (initial, warning)| `<null>` |
| `transformOrigin=(null)`| (initial)| `<null>` |
| `transformOrigin=(undefined)`| (initial)| `<null>` |

## `type` (on `<button>` inside `<div>`)
| Test Case | Flags | Result |
| --- | --- | --- |
Expand Down
10 changes: 10 additions & 0 deletions fixtures/attribute-behavior/src/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -1981,6 +1981,16 @@ const attributes = [
overrideStringValue:
'translate(-10,-20) scale(2) rotate(45) translate(5,10)',
},
{
name: 'transform-origin',
tagName: 'svg',
read: getSVGAttribute('transform-origin'),
},
{
name: 'transformOrigin',
tagName: 'svg',
read: getSVGAttribute('transform-origin'),
},
{name: 'type', tagName: 'button', overrideStringValue: 'reset'},
{
name: 'type',
Expand Down
8 changes: 4 additions & 4 deletions fixtures/flight-browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h1>Flight Example</h1>
<script src="../../build/node_modules/react-dom/umd/react-dom.development.js"></script>
<script src="../../build/node_modules/react-dom/umd/react-dom-server.browser.development.js"></script>
<script src="../../build/node_modules/react-server-dom-webpack/umd/react-server-dom-webpack-server.browser.development.js"></script>
<script src="../../build/node_modules/react-server-dom-webpack/umd/react-server-dom-webpack.development.js"></script>
<script src="../../build/node_modules/react-server-dom-webpack/umd/react-server-dom-webpack-client.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6/babel.js"></script>
<script type="text/babel">
let Suspense = React.Suspense;
Expand Down Expand Up @@ -60,7 +60,7 @@ <h1>Flight Example</h1>
content: <HTML />,
};

let stream = ReactServerDOMWriter.renderToReadableStream(model);
let stream = ReactServerDOMServer.renderToReadableStream(model);
let response = new Response(stream, {
headers: {'Content-Type': 'text/html'},
});
Expand All @@ -70,13 +70,13 @@ <h1>Flight Example</h1>
let blob = await responseToDisplay.blob();
let url = URL.createObjectURL(blob);

let data = ReactServerDOMReader.createFromFetch(
let data = ReactServerDOMClient.createFromFetch(
fetch(url)
);
// The client also supports XHR streaming.
// var xhr = new XMLHttpRequest();
// xhr.open('GET', url);
// let data = ReactServerDOMReader.createFromXHR(xhr);
// let data = ReactServerDOMClient.createFromXHR(xhr);
// xhr.send();

renderResult(data);
Expand Down
9 changes: 8 additions & 1 deletion fixtures/flight/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,14 @@ module.exports = function (webpackEnv) {
// },
// }),
// Fork Start
new ReactFlightWebpackPlugin({isServer: false}),
new ReactFlightWebpackPlugin({
isServer: false,
clientReferences: {
directory: './src',
recursive: true,
include: /\.(js|ts|jsx|tsx)$/,
},
}),
// Fork End
].filter(Boolean),
// Turn off performance processing because we utilize
Expand Down
30 changes: 26 additions & 4 deletions fixtures/flight/loader/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import {
resolve,
getSource,
load as reactLoad,
getSource as getSourceImpl,
transformSource as reactTransformSource,
} from 'react-server-dom-webpack/node-loader';

export {resolve, getSource};
export {resolve};

import babel from '@babel/core';

Expand All @@ -17,6 +18,23 @@ const babelOptions = {
],
};

async function babelLoad(url, context, defaultLoad) {
const {format} = context;
const result = await defaultLoad(url, context, defaultLoad);
if (result.format === 'module') {
const opt = Object.assign({filename: url}, babelOptions);
const {code} = await babel.transformAsync(result.source, opt);
return {source: code, format: 'module'};
}
return defaultLoad(url, context, defaultLoad);
}

export async function load(url, context, defaultLoad) {
return await reactLoad(url, context, (u, c) => {
return babelLoad(u, c, defaultLoad);
});
}

async function babelTransformSource(source, context, defaultTransformSource) {
const {format} = context;
if (format === 'module') {
Expand All @@ -27,8 +45,12 @@ async function babelTransformSource(source, context, defaultTransformSource) {
return defaultTransformSource(source, context, defaultTransformSource);
}

export async function transformSource(source, context, defaultTransformSource) {
return reactTransformSource(source, context, (s, c) => {
async function transformSourceImpl(source, context, defaultTransformSource) {
return await reactTransformSource(source, context, (s, c) => {
return babelTransformSource(s, c, defaultTransformSource);
});
}

export const transformSource =
process.version < 'v16' ? transformSourceImpl : undefined;
export const getSource = process.version < 'v16' ? getSourceImpl : undefined;
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const app = express();

// Application
app.get('/', function (req, res) {
require('./handler.server.js')(req, res);
require('./handler.js')(req, res);
});

app.get('/todos', function (req, res) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const {resolve} = require('path');
const React = require('react');

module.exports = function (req, res) {
// const m = require('../src/App.server.js');
import('../src/App.server.js').then(m => {
// const m = require('../src/App.js');
import('../src/App.js').then(m => {
const dist = process.env.NODE_ENV === 'development' ? 'dist' : 'build';
readFile(
resolve(__dirname, `../${dist}/react-client-manifest.json`),
Expand Down
2 changes: 1 addition & 1 deletion fixtures/flight/server/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"type": "commonjs",
"main": "./cli.server.js"
"main": "./cli.js"
}
12 changes: 6 additions & 6 deletions fixtures/flight/src/App.server.js → fixtures/flight/src/App.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as React from 'react';
import {fetch} from 'react-fetch';

import Container from './Container.js';

import {Counter} from './Counter.client.js';
import {Counter as Counter2} from './Counter2.client.js';
import {Counter} from './Counter.js';
import {Counter as Counter2} from './Counter2.js';

import ShowMore from './ShowMore.client.js';
import ShowMore from './ShowMore.js';

export default function App() {
const todos = fetch('http://localhost:3001/todos').json();
export default async function App() {
const res = await fetch('http://localhost:3001/todos');
const todos = await res.json();
return (
<Container>
<h1>Hello, world</h1>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import * as React from 'react';

import Container from './Container.js';
Expand Down
1 change: 0 additions & 1 deletion fixtures/flight/src/Counter2.client.js

This file was deleted.

3 changes: 3 additions & 0 deletions fixtures/flight/src/Counter2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use client';

export * from './Counter.js';
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use client';

import * as React from 'react';

import Container from './Container.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

export * from 'react-client/src/ReactFlightClientHostConfigBrowser';
export * from 'react-client/src/ReactFlightClientHostConfigStream';
export * from 'react-server-dom-webpack/src/ReactFlightClientWebpackBundlerConfig';
1 change: 1 addition & 0 deletions packages/react-devtools-core/src/standalone.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ function initialize(socket: WebSocket) {
store = new Store(bridge, {
checkBridgeProtocolCompatibility: true,
supportsNativeInspection: true,
supportsTraceUpdates: true,
});

log('Connected');
Expand Down
63 changes: 44 additions & 19 deletions packages/react-devtools-extensions/src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,31 @@ if (!IS_FIREFOX) {
// It's critical since it allows us to directly run scripts on the "main" world on the page
// "document_start" allows it to run before the page's scripts
// so the hook can be detected by react reconciler
chrome.scripting.registerContentScripts([
{
id: 'hook',
matches: ['<all_urls>'],
js: ['build/installHook.js'],
runAt: 'document_start',
world: chrome.scripting.ExecutionWorld.MAIN,
},
{
id: 'renderer',
matches: ['<all_urls>'],
js: ['build/renderer.js'],
runAt: 'document_start',
world: chrome.scripting.ExecutionWorld.MAIN,
chrome.scripting.registerContentScripts(
[
{
id: 'hook',
matches: ['<all_urls>'],
js: ['build/installHook.js'],
runAt: 'document_start',
world: chrome.scripting.ExecutionWorld.MAIN,
},
{
id: 'renderer',
matches: ['<all_urls>'],
js: ['build/renderer.js'],
runAt: 'document_start',
world: chrome.scripting.ExecutionWorld.MAIN,
},
],
function () {
// When the content scripts are already registered, an error will be thrown.
// It happens when the service worker process is incorrectly duplicated.
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError);
}
},
]);
);
}

chrome.runtime.onConnect.addListener(function (port) {
Expand All @@ -51,7 +60,7 @@ chrome.runtime.onConnect.addListener(function (port) {
ports[tab][name] = port;

if (ports[tab].devtools && ports[tab]['content-script']) {
doublePipe(ports[tab].devtools, ports[tab]['content-script']);
doublePipe(ports[tab].devtools, ports[tab]['content-script'], tab);
}
});

Expand All @@ -70,20 +79,36 @@ function installProxy(tabId: number) {
}
}

function doublePipe(one, two) {
function doublePipe(one, two, tabId) {
one.onMessage.addListener(lOne);
function lOne(message) {
two.postMessage(message);
try {
two.postMessage(message);
} catch (e) {
if (__DEV__) {
console.log(`Broken pipe ${tabId}: `, e);
}
shutdown();
}
}
two.onMessage.addListener(lTwo);
function lTwo(message) {
one.postMessage(message);
try {
one.postMessage(message);
} catch (e) {
if (__DEV__) {
console.log(`Broken pipe ${tabId}: `, e);
}
shutdown();
}
}
function shutdown() {
one.onMessage.removeListener(lOne);
two.onMessage.removeListener(lTwo);
one.disconnect();
two.disconnect();
// clean up so that we can rebuild the double pipe if the page is reloaded
ports[tabId] = null;
}
one.onDisconnect.addListener(shutdown);
two.onDisconnect.addListener(shutdown);
Expand Down
4 changes: 2 additions & 2 deletions packages/react-devtools-shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
"@reach/menu-button": "^0.16.1",
"@reach/tooltip": "^0.16.0",
"clipboard-js": "^0.3.6",
"compare-versions": "^5.0.3",
"json5": "^2.1.3",
"local-storage-fallback": "^4.1.1",
"lodash.throttle": "^4.1.1",
"memoize-one": "^3.1.1",
"react-virtualized-auto-sizer": "^1.0.6",
"semver": "^6.3.0"
"react-virtualized-auto-sizer": "^1.0.6"
}
}
Loading

0 comments on commit 3f8db9b

Please sign in to comment.