Skip to content

Commit

Permalink
fix(react-router): Fix SyntaxError in ScriptOnce by escaping single q…
Browse files Browse the repository at this point in the history
…uotes in console.info (#2731)

* Escape single quotes on ScriptOnce

* ci: apply automated fixes

* Update approach to use jsesc to cover more potential scenarios

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
adrifer and autofix-ci[bot] authored Nov 11, 2024
1 parent 32c9ff8 commit 1e5bbbb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/react-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@
"dependencies": {
"@tanstack/history": "workspace:*",
"@tanstack/react-store": "^0.5.6",
"jsesc": "^3.0.2",
"tiny-invariant": "^1.3.3",
"tiny-warning": "^1.0.3"
},
"devDependencies": {
"@types/jsesc": "^3.0.3",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.0.1",
"@vitejs/plugin-react": "^4.3.3",
Expand Down
5 changes: 4 additions & 1 deletion packages/react-router/src/ScriptOnce.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import jsesc from 'jsesc'

export function ScriptOnce({
className,
children,
Expand All @@ -16,7 +18,8 @@ export function ScriptOnce({
__html: [
children,
(log ?? true) && process.env.NODE_ENV === 'development'
? "console.info('Injected From Server:\\n" + children + "');"
? `console.info(\`Injected From Server:
${jsesc(children.toString(), { quotes: 'backtick' })}\`)`
: '',
]
.filter(Boolean)
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1e5bbbb

Please sign in to comment.