Skip to content

Commit f653987

Browse files
feat: add data hydration support with environment variable configuration
1 parent a652a72 commit f653987

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

.github/workflows/attest-and-deploy.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ jobs:
3737
format: 'spdx-json'
3838
output-file: 'sbom.spdx.json'
3939

40-
# Build the site using the build script in package.json
41-
- name: Build site
40+
# Build the site using the build script in package.json with data hydration enabled
41+
- name: Build site with data hydration
4242
run: npm run build
43+
env:
44+
VITE_ENABLE_DATA_HYDRATION: 'true'
4345

4446
# Package the build into a tarball so it can be easily verified
4547
- name: Package the build

.github/workflows/ci-cd.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ jobs:
2929
- name: Install dependencies
3030
run: npm ci
3131

32-
- name: Build application
32+
- name: Build application (without data hydration)
3333
run: npm run build
34+
env:
35+
VITE_ENABLE_DATA_HYDRATION: 'false'
3436

3537
- name: Run tests
3638
run: npm test

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,25 @@ A task management application that allows users to create, organize, and filter
5353
### Available Scripts
5454

5555
- `npm start` - Start the development server
56-
- `npm test` - Run tests with Vitest
56+
- `npm start:hydrated` - Start the development server with data hydration enabled
5757
- `npm run build` - Build for production
58+
- `npm run build:hydrated` - Build for production with data hydration enabled
59+
- `npm run build:clean` - Build for production with data hydration explicitly disabled
5860
- `npm run preview` - Preview the production build locally
61+
- `npm run preview:hydrated` - Preview the production build with data hydration enabled
62+
- `npm test` - Run tests with Vitest
63+
64+
### Data Hydration
65+
66+
The application supports pre-populating the app with sample data through an optional hydration process:
67+
68+
- Sample data is defined in `src/data/initialData.json`
69+
- Hydration can be enabled/disabled using the `VITE_ENABLE_DATA_HYDRATION` environment variable
70+
- Use the convenience scripts for development with hydration:
71+
- `npm run start:hydrated` - Development with sample data
72+
- `npm run build:hydrated` - Production build with sample data
73+
- `npm run build:clean` - Production build without sample data
74+
- GitHub Actions deployment automatically enables hydration for the production build
5975

6076
## Architecture
6177

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@
2121
},
2222
"scripts": {
2323
"start": "BROWSER=none WDS_SOCKET_PORT=0 vite --port 3000",
24+
"start:hydrated": "VITE_ENABLE_DATA_HYDRATION=true BROWSER=none WDS_SOCKET_PORT=0 vite --port 3000",
2425
"build": "vite build",
26+
"build:hydrated": "VITE_ENABLE_DATA_HYDRATION=true vite build",
27+
"build:clean": "VITE_ENABLE_DATA_HYDRATION=false vite build",
2528
"preview": "vite preview",
29+
"preview:hydrated": "VITE_ENABLE_DATA_HYDRATION=true vite preview",
2630
"test": "vitest",
2731
"build:css": "tailwindcss build src/index.css -o src/output.css",
2832
"watch:css": "tailwindcss -i src/index.css -o src/output.css --watch"

src/common/utils/DataHydrationService.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ export const DataHydrationService = {
3434
* @returns {boolean}
3535
*/
3636
shouldHydrate: () => {
37-
// You can add logic here to check if hydration should occur
38-
// For example, checking if it's the first time the app is run
39-
return true;
37+
// Check if the VITE_ENABLE_DATA_HYDRATION environment variable is set to 'true'
38+
// This allows controlling hydration via build configuration or environment
39+
return import.meta.env.VITE_ENABLE_DATA_HYDRATION === 'true';
4040
}
4141
};

0 commit comments

Comments
 (0)