Skip to content

Commit

Permalink
[plugin-react-refresh] Solve the problem with MobX observer() HOC (#3015
Browse files Browse the repository at this point in the history
)

* [plugin-react-refresh] Solve the problem with MobX observer() HOC

* [plugin-react-refresh] Solve the problem with MobX observer() HOC

* [plugin-react-refresh] Update the testing snapshot
  • Loading branch information
yuhongda authored Mar 30, 2021
1 parent a17dd97 commit 6e4bb7f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
8 changes: 5 additions & 3 deletions plugins/plugin-react-refresh/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ const reactRefreshCode = fs

function transformHtml(contents) {
return contents.replace(
/<body.*?>/s,
`$&
/(.*)(<body.*?>)(.*)/s,
function (match, p1, p2, p3) {
return `${p1}${p2}
<script>
function debounce(e,t){let u;return()=>{clearTimeout(u),u=setTimeout(e,t)}}
{
Expand All @@ -27,7 +28,8 @@ function transformHtml(contents) {
window.$RefreshReg$ = () => {};
window.$RefreshSig$ = () => (type) => type;
}
</script>`,
</script>${p3}`
},
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ function register(type, id) {
allFamiliesByType.set(type, family); // Visit inner types because we might not have registered them.
if (typeof type === 'object' && type !== null) {
switch (type.$typeof) {
switch (type.$$typeof) {
case REACT_FORWARD_REF_TYPE:
register(type.render, id + '$render');
break;
Expand Down Expand Up @@ -653,7 +653,7 @@ function isLikelyComponentType(type) {
case 'object':
{
if (type != null) {
switch (type.$typeof) {
switch (type.$$typeof) {
case REACT_FORWARD_REF_TYPE:
case REACT_MEMO_TYPE:
// Definitely React components.
Expand Down Expand Up @@ -1083,7 +1083,7 @@ function register(type, id) {
allFamiliesByType.set(type, family); // Visit inner types because we might not have registered them.
if (typeof type === 'object' && type !== null) {
switch (type.$typeof) {
switch (type.$$typeof) {
case REACT_FORWARD_REF_TYPE:
register(type.render, id + '$render');
break;
Expand Down Expand Up @@ -1366,7 +1366,7 @@ function isLikelyComponentType(type) {
case 'object':
{
if (type != null) {
switch (type.$typeof) {
switch (type.$$typeof) {
case REACT_FORWARD_REF_TYPE:
case REACT_MEMO_TYPE:
// Definitely React components.
Expand Down Expand Up @@ -1785,7 +1785,7 @@ function register(type, id) {
allFamiliesByType.set(type, family); // Visit inner types because we might not have registered them.
if (typeof type === 'object' && type !== null) {
switch (type.$typeof) {
switch (type.$$typeof) {
case REACT_FORWARD_REF_TYPE:
register(type.render, id + '$render');
break;
Expand Down Expand Up @@ -2068,7 +2068,7 @@ function isLikelyComponentType(type) {
case 'object':
{
if (type != null) {
switch (type.$typeof) {
switch (type.$$typeof) {
case REACT_FORWARD_REF_TYPE:
case REACT_MEMO_TYPE:
// Definitely React components.
Expand Down

1 comment on commit 6e4bb7f

@vercel
Copy link

@vercel vercel bot commented on 6e4bb7f Mar 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.