Skip to content

Commit

Permalink
feat(repo): Add Vite React Typescript playground app (#1424)
Browse files Browse the repository at this point in the history
* feat(repo): Add Vite React Typescript playground app

* fix(clerk-react): Correctly polyfill window.global for vite prod builds

Co-Authored-By: Nikos Douvlis <nikosdouvlis@gmail.com>

* chore(clerk-react): Add changeset

* fix(repo): Remove the env var check from React Vite playground

---------

Co-authored-by: Nikos Douvlis <nikosdouvlis@gmail.com>
  • Loading branch information
anagstef and nikosdouvlis authored Jun 28, 2023
1 parent d4b289c commit 1e71b60
Show file tree
Hide file tree
Showing 19 changed files with 484 additions and 41 deletions.
5 changes: 5 additions & 0 deletions .changeset/wild-seals-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-react': minor
---

Fix `global is not defined` error when using Vite + React
78 changes: 39 additions & 39 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions packages/react/src/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* https://vitejs.dev/config/#define
* We are solving this in the SDK level to reduce setup steps.
*/
if (typeof global === 'undefined' && typeof window !== 'undefined' && !window.global) {
(window as any).global = window;
if (typeof window !== 'undefined' && !window.global) {
window.global = typeof global === 'undefined' ? window : global;
}

export {};
1 change: 1 addition & 0 deletions playground/vite-react-ts/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_REACT_APP_CLERK_PUBLISHABLE_KEY=pk_test_************
14 changes: 14 additions & 0 deletions playground/vite-react-ts/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
parser: '@typescript-eslint/parser',
parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': 'warn',
},
}
24 changes: 24 additions & 0 deletions playground/vite-react-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
13 changes: 13 additions & 0 deletions playground/vite-react-ts/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Clerk + React + Vite</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
34 changes: 34 additions & 0 deletions playground/vite-react-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "vite-react-ts",
"private": true,
"version": "0.1.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"dev:yalc": "npm run yalc && vite",
"yalc": "yalc add -- @clerk/clerk-react @clerk/types @clerk/shared"
},
"dependencies": {
"@clerk/clerk-react": "file:.yalc/@clerk/clerk-react",
"@clerk/shared": "file:.yalc/@clerk/shared",
"@clerk/types": "file:.yalc/@clerk/types",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.14.0"
},
"devDependencies": {
"@types/react": "^18.0.37",
"@types/react-dom": "^18.0.11",
"@typescript-eslint/eslint-plugin": "^5.59.0",
"@typescript-eslint/parser": "^5.59.0",
"@vitejs/plugin-react": "^4.0.0",
"eslint": "^8.38.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.3.4",
"typescript": "^5.0.2",
"vite": "^4.3.9"
}
}
17 changes: 17 additions & 0 deletions playground/vite-react-ts/public/clerk.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions playground/vite-react-ts/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions playground/vite-react-ts/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}

@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}

.card {
padding: 2em;
}

.read-the-docs {
color: #888;
}

ul {
padding: 0;
}

li {
list-style: none;
}

nav {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
Loading

0 comments on commit 1e71b60

Please sign in to comment.