Skip to content

Commit

Permalink
Initial SSR refactor (#9102)
Browse files Browse the repository at this point in the history
* changes

* asd

* fix tests

* fix lint

* fix ts

* fix ts

* cleanup

* cleanup

* fix

* Apply suggestions from code review

Co-authored-by: Yuichiro Tachibana (Tsuchiya) <[email protected]>

* fix

* add changeset

* fix gitignore

* fix changeset

* fix lockfile

* format

* fix

* add changeset

* githunore

* kit bopilerplate

* add changeset

* fix website

* add changeset

---------

Co-authored-by: Yuichiro Tachibana (Tsuchiya) <[email protected]>
Co-authored-by: gradio-pr-bot <[email protected]>
  • Loading branch information
3 people authored Aug 14, 2024
1 parent f6b2b97 commit efdc323
Show file tree
Hide file tree
Showing 244 changed files with 9,859 additions and 982 deletions.
19 changes: 19 additions & 0 deletions .changeset/wise-buttons-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
"@gradio/audio": patch
"@gradio/build": patch
"@gradio/button": patch
"@gradio/chatbot": patch
"@gradio/core": patch
"@gradio/dataframe": patch
"@gradio/lite": patch
"@gradio/plot": patch
"@gradio/spa": patch
"@gradio/storybook": patch
"@gradio/video": patch
"@gradio/wasm": patch
"app": patch
"gradio": patch
"website": patch
---

feat:Initial SSR refactor
2 changes: 1 addition & 1 deletion .config/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
**/.mypy_cache/**
!test-strategy.md
**/js/_space-test/**
../js/app/src/lite/theme.css
../js/lite/src/theme.css
../js/storybook/theme.css
**/gradio_cached_examples/**
**/storybook-static/**
Expand Down
3 changes: 2 additions & 1 deletion .config/.prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"singleQuote": false,
"trailingComma": "none",
"printWidth": 80,
"plugins": ["prettier-plugin-svelte"]
"plugins": ["prettier-plugin-svelte"],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
}
2 changes: 1 addition & 1 deletion .config/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default [
"**/*.spec.ts",
"**/*.test.ts",
"**/*.node-test.ts",
"js/app/test/**/*",
"js/spa/test/**/*",
"**/*vite.config.ts",
"**/_website/**/*",
"**/_spaces-test/**/*",
Expand Down
2 changes: 1 addition & 1 deletion .config/playwright-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kl from "kleur";

const __dirname = fileURLToPath(new URL(".", import.meta.url));
const TEST_APP_PATH = join(__dirname, "./test.py");
const TEST_FILES_PATH = join(__dirname, "..", "js", "app", "test");
const TEST_FILES_PATH = join(__dirname, "..", "js", "spa", "test");
const ROOT = join(__dirname, "..");

const test_files = readdirSync(TEST_FILES_PATH)
Expand Down
2 changes: 1 addition & 1 deletion .config/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import config from "../js/app/vite.config";
import config from "../js/spa/vite.config";

export default config;
2 changes: 1 addition & 1 deletion .github/actions/install-frontend-deps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ runs:
run: |
. venv/bin/activate
python -m pip install -U build hatch packaging>=23.2 # packaging>=23.2 is needed to build Lite due to https://github.com/pypa/hatch/issues/1381
pnpm --filter @gradio/app build:lite
pnpm --filter @gradio/lite build
2 changes: 1 addition & 1 deletion .github/workflows/test-functional-lite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
- name: Run Lite E2E tests
run: |
. venv/bin/activate
pnpm --filter @gradio/app test:browser:lite
pnpm --filter @gradio/lite test:browser
- name: Get the performance result
run: |
export LITE_APP_LOAD_TIME=$(jq -r '.app_load_time' .lite-perf.json)
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/trigger-changeset.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
types: [opened, synchronize, reopened, edited, labeled, unlabeled]
branches:
- main
- 5.0-dev
issue_comment:
types: [edited]

Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ __pycache__/
*.py[cod]
*$py.class
build/
!js/build/
!js/build/dist/
__tmp/*
*.pyi
!gradio/stubs/**/*.pyi
py.typed
.ipynb_checkpoints/
.python-version
=23.2

# JS build
gradio/templates/*
Expand All @@ -38,6 +41,8 @@ coverage.xml
test.txt
**/snapshots/**/*.png
playwright-report/
.hypothesis
.lite-perf.json

# Demos
demo/tmp.zip
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
},
"typescript.tsdk": "node_modules/typescript/lib",
"i18n-ally.localesPaths": [
"js/app/src/lang"
"js/spa/src/lang"
]
}
49 changes: 0 additions & 49 deletions =23.2

This file was deleted.

6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ bash scripts/run_all_tests.sh
pnpm test
```

- Browser tests are located in `js/app/test` and are defined as `*spec.ts` files. To run browser tests:
- Browser tests are located in `js/spa/test` and are defined as `*spec.ts` files. To run browser tests:

```
pnpm test:browser
Expand Down Expand Up @@ -257,7 +257,7 @@ bash scripts/run_lite.sh

If you make changes to the Python code during development, you will need to rebuild the Python packages loaded to Graio-Lite. To do this, run:
```
pnpm --filter @gradio/app pybuild
pnpm --filter @gradio/lite pybuild
```

To generate the release build, run:
Expand Down Expand Up @@ -309,7 +309,7 @@ Verify that you've used the correct filename of your gradio app, and that you're

---

```ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL @gradio/app@1.0.0 build:local: vite build --mode production:local --emptyOutDir "--emptyOutDir"```
```ERR_PNPM_RECURSIVE_RUN_FIRST_FAIL @gradio/spa@1.0.0 build:local: vite build --mode production:local --emptyOutDir "--emptyOutDir"```

Delete `/node_modules` and `pnpm-lock.yaml`:

Expand Down
1 change: 0 additions & 1 deletion gradio/hash_seed.txt

This file was deleted.

3 changes: 2 additions & 1 deletion js/_website/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { sveltekit } from "@sveltejs/kit/vite";
import { defineConfig } from "vite";
import { inject_component_loader } from "../app/build_plugins";
import { inject_component_loader } from "../build/dist/index.js";

//@ts-ignore
export default defineConfig(({ mode }) => ({
plugins: [sveltekit(), inject_component_loader({ mode })]
}));
159 changes: 0 additions & 159 deletions js/_website/vite.config.ts.timestamp-1721955124085-e178b44edfdf6.mjs

This file was deleted.

22 changes: 21 additions & 1 deletion js/app/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
/src/lite/theme.css
node_modules

# Output
.output
.vercel
/.svelte-kit
/build

# OS
.DS_Store
Thumbs.db

# Env
.env
.env.*
!.env.example
!.env.test

# Vite
vite.config.js.timestamp-*
vite.config.ts.timestamp-*
38 changes: 38 additions & 0 deletions js/app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# create-svelte

Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/main/packages/create-svelte).

## Creating a project

If you're seeing this, you've probably already done this step. Congrats!

```bash
# create a new project in the current directory
npm create svelte@latest

# create a new project in my-app
npm create svelte@latest my-app
```

## Developing

Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:

```bash
npm run dev

# or start the server and open the app in a new browser tab
npm run dev -- --open
```

## Building

To create a production version of your app:

```bash
npm run build
```

You can preview the production build with `npm run preview`.

> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
108 changes: 19 additions & 89 deletions js/app/package.json
Original file line number Diff line number Diff line change
@@ -1,96 +1,26 @@
{
"name": "@gradio/app",
"version": "1.39.2",
"name": "app",
"version": "0.0.1",
"private": true,
"type": "module",
"scripts": {
"dev": "vite --port 9876",
"dev:lite": "run-p dev:lite:*",
"dev:lite:self": "vite --port 9876 --mode development:lite",
"dev:lite:worker": "pnpm --filter @gradio/wasm dev",
"build": "vite build --mode production --emptyOutDir",
"cssbuild": "python ../../scripts/generate_theme.py --outfile ./src/lite/theme.css",
"pybuild:gradio": "cd ../../ && hatch build -t lite",
"pybuild:gradio-client": "cd ../../client/python && python -m build",
"pybuild": "run-p pybuild:*",
"build:lite": "pnpm pybuild && pnpm cssbuild && pnpm --filter @gradio/client build && pnpm --filter @gradio/wasm build && vite build --mode production:lite",
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"test:snapshot": "pnpm exec playwright test snapshots/ --config=../../.config/playwright.config.js",
"test:browser": "pnpm exec playwright test test/ --grep-invert 'reload.spec.ts' --config=../../.config/playwright.config.js",
"test:browser:dev": "pnpm exec playwright test test/ --ui --config=../../.config/playwright.config.js",
"test:browser:reload": "CI=1 pnpm exec playwright test test/ --grep 'reload.spec.ts' --config=../../.config/playwright.config.js",
"test:browser:lite": "GRADIO_E2E_TEST_LITE=1 pnpm test:browser",
"test:browser:lite:dev": "GRADIO_E2E_TEST_LITE=1 pnpm test:browser:dev",
"build:css": "pollen -c pollen.config.cjs -o src/pollen-dev.css"
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check .",
"format": "prettier --write ."
},
"dependencies": {
"@gradio/accordion": "workspace:^",
"@gradio/annotatedimage": "workspace:^",
"@gradio/atoms": "workspace:^",
"@gradio/audio": "workspace:^",
"@gradio/box": "workspace:^",
"@gradio/button": "workspace:^",
"@gradio/chatbot": "workspace:^",
"@gradio/checkbox": "workspace:^",
"@gradio/checkboxgroup": "workspace:^",
"@gradio/client": "workspace:^",
"@gradio/code": "workspace:^",
"@gradio/colorpicker": "workspace:^",
"@gradio/column": "workspace:^",
"@gradio/dataframe": "workspace:^",
"@gradio/dataset": "workspace:^",
"@gradio/datetime": "workspace:^",
"@gradio/downloadbutton": "workspace:^",
"@gradio/dropdown": "workspace:^",
"@gradio/fallback": "workspace:^",
"@gradio/file": "workspace:^",
"@gradio/fileexplorer": "workspace:^",
"@gradio/form": "workspace:^",
"@gradio/gallery": "workspace:^",
"@gradio/group": "workspace:^",
"@gradio/highlightedtext": "workspace:^",
"@gradio/html": "workspace:^",
"@gradio/icons": "workspace:^",
"@gradio/image": "workspace:^",
"@gradio/imageeditor": "workspace:^",
"@gradio/json": "workspace:^",
"@gradio/label": "workspace:^",
"@gradio/markdown": "workspace:^",
"@gradio/model3d": "workspace:^",
"@gradio/multimodaltextbox": "workspace:^",
"@gradio/nativeplot": "workspace:^",
"@gradio/number": "workspace:^",
"@gradio/paramviewer": "workspace:^",
"@gradio/plot": "workspace:^",
"@gradio/radio": "workspace:^",
"@gradio/row": "workspace:^",
"@gradio/simpledropdown": "workspace:^",
"@gradio/simpleimage": "workspace:^",
"@gradio/simpletextbox": "workspace:^",
"@gradio/slider": "workspace:^",
"@gradio/state": "workspace:^",
"@gradio/statustracker": "workspace:^",
"@gradio/tabitem": "workspace:^",
"@gradio/tabs": "workspace:^",
"@gradio/textbox": "workspace:^",
"@gradio/theme": "workspace:^",
"@gradio/timer": "workspace:^",
"@gradio/upload": "workspace:^",
"@gradio/uploadbutton": "workspace:^",
"@gradio/utils": "workspace:^",
"@gradio/video": "workspace:^",
"@gradio/wasm": "workspace:^",
"@huggingface/space-header": "^1.0.3",
"@types/eventsource": "^1.1.15",
"cross-env": "^7.0.3",
"d3-dsv": "^3.0.1",
"eventsource": "^2.0.2",
"mime-types": "^2.1.34",
"postcss": "^8.4.21",
"postcss-prefix-selector": "^1.16.0"
"devDependencies": {
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.1.2",
"svelte": "^4.2.7",
"svelte-check": "^3.6.0",
"typescript": "^5.0.0",
"vite": "^5.0.3"
},
"msw": {
"workerDirectory": "public"
},
"main_changeset": true
"type": "module"
}
13 changes: 13 additions & 0 deletions js/app/src/app.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
// interface Locals {}
// interface PageData {}
// interface PageState {}
// interface Platform {}
}
}

export {};
Loading

0 comments on commit efdc323

Please sign in to comment.