-
Notifications
You must be signed in to change notification settings - Fork 26.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix cases for the
optimize_server_react
transform (#59390)
- Loading branch information
Showing
7 changed files
with
147 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 10 additions & 4 deletions
14
packages/next-swc/crates/core/tests/fixture/optimize_server_react/3/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
packages/next-swc/crates/core/tests/fixture/optimize_server_react/6/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { useState, useEffect, useLayoutEffect } from 'react' | ||
import React from 'react' | ||
|
||
const Component = ({ children, fallback }) => { | ||
const [mounted, setMounted] = useState(false) | ||
useEffect(() => setMounted(true), []) | ||
if (!mounted) { | ||
return fallback ?? /* @__PURE__ */ jsx(Fragment, {}) | ||
} | ||
return children | ||
} | ||
export { Component } |
14 changes: 14 additions & 0 deletions
14
packages/next-swc/crates/core/tests/fixture/optimize_server_react/6/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { useState, useEffect, useLayoutEffect } from 'react'; | ||
import React from 'react'; | ||
const Component = ({ children, fallback })=>{ | ||
const [mounted, setMounted] = [ | ||
false, | ||
()=>null | ||
]; | ||
null; | ||
if (!mounted) { | ||
return fallback ?? /* @__PURE__ */ jsx(Fragment, {}); | ||
} | ||
return children; | ||
}; | ||
export { Component }; |
31 changes: 31 additions & 0 deletions
31
packages/next-swc/crates/core/tests/fixture/optimize_server_react/7/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useEffect, useLayoutEffect, useMemo } from 'react' | ||
import * as React from 'react' | ||
|
||
export default function App() { | ||
useEffect(() => { | ||
console.log('Hello World') | ||
}, []) | ||
|
||
useLayoutEffect(() => { | ||
function foo() {} | ||
return () => {} | ||
}, [1, 2, App]) | ||
|
||
useLayoutEffect(() => {}, [runSideEffect()]) | ||
useEffect(() => {}, [1, runSideEffect(), 2]) | ||
useEffect(() => {}, getArray()) | ||
|
||
const a = useMemo(() => { | ||
return 1 | ||
}, []) | ||
|
||
React.useEffect(() => { | ||
console.log('Hello World') | ||
}) | ||
|
||
return ( | ||
<div> | ||
<h1>Hello World</h1> | ||
</div> | ||
) | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/next-swc/crates/core/tests/fixture/optimize_server_react/7/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { useEffect, useLayoutEffect, useMemo } from 'react'; | ||
import * as React from 'react'; | ||
export default function App() { | ||
null; | ||
null; | ||
useLayoutEffect(()=>{}, [ | ||
runSideEffect() | ||
]); | ||
useEffect(()=>{}, [ | ||
1, | ||
runSideEffect(), | ||
2 | ||
]); | ||
useEffect(()=>{}, getArray()); | ||
const a = useMemo(()=>{ | ||
return 1; | ||
}, []); | ||
React.useEffect(()=>{ | ||
console.log('Hello World'); | ||
}); | ||
return <div> | ||
|
||
<h1>Hello World</h1> | ||
|
||
</div>; | ||
} |