Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit335ccd0

Browse files
authored
fix fragment issue (#217)
1 parent1953ee5 commit335ccd0

File tree

4 files changed

+75
-2
lines changed

4 files changed

+75
-2
lines changed

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name":"react-router-devtools",
33
"description":"Devtools for React Router - debug, trace, find hydration errors, catch bugs and inspect server/client data with react-router-devtools",
44
"author":"Alem Tuzlak",
5-
"version":"5.1.0",
5+
"version":"5.1.1",
66
"license":"MIT",
77
"keywords": [
88
"react-router",

‎src/client/layout/Tabs.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const Tabs = ({ plugins, setIsOpen }: TabsProps) => {
9090
}
9191

9292
constgetErrorCount=()=>{
93-
returnhtmlErrors.length+(window.HYDRATION_OVERLAY.ERROR ?1 :0)
93+
returnhtmlErrors.length+(window.HYDRATION_OVERLAY?.ERROR ?1 :0)
9494
}
9595

9696
consthasErrors=getErrorCount()>0

‎src/vite/utils/inject-source.test.ts‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,64 @@ const removeEmptySpace = (str: string) => {
66
}
77

88
describe("inject source",()=>{
9+
it("shouldn't augment react fragments",()=>{
10+
constoutput=removeEmptySpace(
11+
addSourceToJsx(
12+
`
13+
export const Route = createFileRoute("/test")({
14+
component: function() { return <>Hello World</> },
15+
})
16+
`,
17+
"test.jsx"
18+
).code
19+
)
20+
expect(output).toBe(
21+
removeEmptySpace(`
22+
export const Route = createFileRoute("/test")({
23+
component: function() { return <>Hello World</> },
24+
})
25+
`)
26+
)
27+
})
28+
29+
it("shouldn't augment react fragments if they start with Fragment ",()=>{
30+
constoutput=removeEmptySpace(
31+
addSourceToJsx(
32+
`
33+
export const Route = createFileRoute("/test")({
34+
component: function() { return <Fragment>Hello World</Fragment> },
35+
})
36+
`,
37+
"test.jsx"
38+
).code
39+
)
40+
expect(output).toBe(
41+
removeEmptySpace(`
42+
export const Route = createFileRoute("/test")({
43+
component: function() { return <Fragment>Hello World</Fragment> },
44+
})
45+
`)
46+
)
47+
})
48+
it("shouldn't augment react fragments if they start with React.Fragment ",()=>{
49+
constoutput=removeEmptySpace(
50+
addSourceToJsx(
51+
`
52+
export const Route = createFileRoute("/test")({
53+
component: function() { return <React.Fragment>Hello World</React.Fragment> },
54+
})
55+
`,
56+
"test.jsx"
57+
).code
58+
)
59+
expect(output).toBe(
60+
removeEmptySpace(`
61+
export const Route = createFileRoute("/test")({
62+
component: function() { return <React.Fragment>Hello World</React.Fragment> },
63+
})
64+
`)
65+
)
66+
})
967
describe("FunctionExpression",()=>{
1068
it("should work with deeply nested custom JSX syntax",()=>{
1169
constoutput=removeEmptySpace(

‎src/vite/utils/inject-source.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,27 @@ const getPropsNameFromFunctionDeclaration = (
8282
returnpropsName
8383
}
8484

85+
constgetNameOfElement=(element:t.JSXIdentifier|t.JSXMemberExpression|t.JSXNamespacedName):string=>{
86+
if(element.type==="JSXIdentifier"){
87+
returnelement.name
88+
}
89+
if(element.type==="JSXMemberExpression"){
90+
return`${getNameOfElement(element.object)}.${getNameOfElement(element.property)}`
91+
}
92+
93+
return`${element.namespace.name}:${element.name.name}`
94+
}
95+
8596
consttransformJSX=(element:NodePath<t.JSXOpeningElement>,propsName:string|null,file:string)=>{
8697
constloc=element.node.loc
8798
if(!loc)return
8899
constline=loc.start.line
89100
constcolumn=loc.start.column
101+
constnameOfElement=getNameOfElement(element.node.name)
90102

103+
if(nameOfElement==="Fragment"||nameOfElement==="React.Fragment"){
104+
return
105+
}
91106
consthasDataSource=element.node.attributes.some(
92107
(attr)=>
93108
attr.type==="JSXAttribute"&&attr.name.type==="JSXIdentifier"&&attr.name.name==="data-rrdt-source"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp