Skip to content

Commit 335ccd0

Browse files
authored
fix fragment issue (#217)
1 parent 1953ee5 commit 335ccd0

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
const getErrorCount = () => {
93-
return htmlErrors.length + (window.HYDRATION_OVERLAY.ERROR ? 1 : 0)
93+
return htmlErrors.length + (window.HYDRATION_OVERLAY?.ERROR ? 1 : 0)
9494
}
9595

9696
const hasErrors = 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+
const output = 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+
const output = 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+
const output = 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
const output = 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
return propsName
8383
}
8484

85+
const getNameOfElement = (element: t.JSXIdentifier | t.JSXMemberExpression | t.JSXNamespacedName): string => {
86+
if (element.type === "JSXIdentifier") {
87+
return element.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
const transformJSX = (element: NodePath<t.JSXOpeningElement>, propsName: string | null, file: string) => {
8697
const loc = element.node.loc
8798
if (!loc) return
8899
const line = loc.start.line
89100
const column = loc.start.column
101+
const nameOfElement = getNameOfElement(element.node.name)
90102

103+
if (nameOfElement === "Fragment" || nameOfElement === "React.Fragment") {
104+
return
105+
}
91106
const hasDataSource = 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)