Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 5 additions & 22 deletions apps/playground/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# react-data-export playground
# react-data-export playground (dev sandbox)

> **Dev sandbox, not deployed.** This app runs in CI (tests and build) and locally. It is not deployed anywhere. The public playground is a separate repository, [`securedeveloper/react-data-export-playground`](https://github.com/securedeveloper/react-data-export-playground), live at https://react-data-export-playground.vercel.app/. It installs the published package from npm.

A Vite + React 19 app that runs the real library in the browser. It is private and never published to npm.

Expand All @@ -7,7 +9,7 @@ A Vite + React 19 app that runs the real library in the browser. It is private a
- **`useExcelExport`**, the hook, with its status, progress, the saved file's size, and a Cancel button while it runs.
- **Table**: a rendered HTML `<table>` (a two-row header with `rowspan`/`colspan`, typed `data-type`/`data-numfmt` cells, a link, a `data-export-ignore` row, a `hidden` row, a footer; `src/demo-table.tsx`) exported with `<ExportTableButton tableRef={ref}>` and with `useTableExport(ref)` behind a custom button. A format choice and a computed-styles toggle, and a preview of the sheet `fromTable` builds from it.

The app imports the workspace package from its TypeScript sources (`vite.config.ts`), so it always matches the branch. Nothing leaves the browser: there are no uploads, analytics, cookies, CDNs or external requests. `vercel.json` sets a strict Content-Security-Policy (`'self'` only), and `vite preview` serves the same headers, so the CSP is exercised locally.
The app imports the workspace package from its TypeScript sources (`vite.config.ts`), so it always matches the branch. Nothing leaves the browser: there are no uploads, analytics, cookies, CDNs or external requests. `vite.config.ts` gives `vite preview` a strict Content-Security-Policy (`'self'` only) and the other security headers, so the CSP gets tested locally.

## Commands (from the repo root)

Expand All @@ -16,24 +18,5 @@ npm ci
npm run dev -w playground # http://localhost:5173
npm test -w playground # option mapping and preview grid (Vitest)
npm run build -w playground # → apps/playground/dist
npm run preview -w playground # serves dist with the production headers
npm run preview -w playground # serves dist with the security headers
```

## Deploying on Vercel (for Afzal; the project is not created yet)

Create a project from `securedeveloper/react-data-export` with:

| Setting | Value |
|---|---|
| Project name | `react-data-export-playground` (gives `react-data-export-playground.vercel.app`) |
| Root Directory | `apps/playground` |
| Framework preset | Vite (also set in `vercel.json`) |
| Install command | `cd ../.. && npm ci` (from `vercel.json`: installs the whole workspace) |
| Build command | `npm run build` (from `vercel.json`) |
| Output directory | `dist` (from `vercel.json`) |
| Node.js version | 24.x (the workspace needs Node ^22.22.2, ^24.15.0 or ≥ 26) |
| Production branch | `main` |

- "Include files outside the root directory in the Build Step" must stay enabled (Vercel's default), because the app builds the library from `../../packages/react-data-export/src`.
- No environment variables are needed.
- The security headers come from `vercel.json`. After the first deploy, check them with `curl -sI https://react-data-export-playground.vercel.app/ | grep -i content-security`.
18 changes: 0 additions & 18 deletions apps/playground/vercel.json

This file was deleted.

17 changes: 10 additions & 7 deletions apps/playground/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';
import react from '@vitejs/plugin-react';
import { defineConfig, type UserConfig } from 'vite';

// Resolve the library from source so the playground always matches the branch
// it is built from, without a separate package build step. The packed tarball
// (what npm users get) is covered by the smoke test and the bundler matrix.
//
// `vite preview` serves the same security headers as Vercel (vercel.json), so
// the Content-Security-Policy is exercised locally before a deploy.
const vercel = JSON.parse(readFileSync(new URL('./vercel.json', import.meta.url), 'utf8')) as {
headers: Array<{ headers: Array<{ key: string; value: string }> }>;

// `vite preview` serves a strict Content-Security-Policy and the other security
// headers (they used to live in vercel.json), so the sandbox and its tests
// exercise the CSP. This app is not deployed; the public playground,
// securedeveloper/react-data-export-playground, sets its own headers.
const headers: Record<string, string> = {
'Content-Security-Policy': "default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; connect-src 'self'; worker-src 'self'; object-src 'none'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'",
'Referrer-Policy': 'no-referrer',
'X-Content-Type-Options': 'nosniff',
'Permissions-Policy': 'camera=(), microphone=(), geolocation=(), interest-cohort=()',
};
const headers = Object.fromEntries(vercel.headers.flatMap((h) => h.headers.map(({ key, value }) => [key, value])));

const config: UserConfig = defineConfig({
plugins: [react()],
Expand Down
Loading