Conversation
|
🚅 Deployed to the one-pr-592 environment in onestack.dev
|
| define: { | ||
| 'process.env.TAMAGUI_IS_SERVER': '"1"', | ||
| 'process.env.VITE_ENVIRONMENT': '"server"', | ||
| 'process.env.VITE_ENVIRONMENT': '"ssr"', |
There was a problem hiding this comment.
actually i think this is a legit bugfix because vite uses ssr other places
There was a problem hiding this comment.
Pull Request Overview
This PR implements server-only and client-only module enforcement for the One framework, preventing code from being incorrectly imported in the wrong environment (server vs client).
- Adds
server-onlyandclient-onlymodules that throw runtime errors when imported in the wrong environment - Creates a Vite plugin to resolve these modules and enforce environment-specific imports
- Includes comprehensive test coverage for both the plugin functionality and end-to-end behavior
Reviewed Changes
Copilot reviewed 14 out of 18 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
packages/one/src/vite/server-only.ts |
Runtime guard that throws error when imported outside SSR environment |
packages/one/src/vite/client-only.ts |
Runtime guard that throws error when imported outside client environment |
packages/one/src/vite/plugins/serverClientOnlyPlugin.ts |
Vite plugin that resolves server-only/client-only imports to custom modules |
packages/one/src/vite/one.ts |
Integrates the server-client-only plugin into the One framework |
packages/vxrn/src/exports/build.ts |
Updates VITE_ENVIRONMENT from "server" to "ssr" for consistency |
tests/test/utils/server-utils.ts |
Example server-only utilities for testing |
tests/test/utils/client-utils.ts |
Example client-only utilities for testing |
tests/test/app/test-server-only+ssr.tsx |
Test page demonstrating server-only functionality |
tests/test/app/test-client-only+spa.tsx |
Test page demonstrating client-only functionality |
tests/test/tests/server-client-only.test.ts |
End-to-end tests verifying server-only/client-only behavior |
| return { | ||
| resolve: { | ||
| alias: { | ||
| 'server-only': resolve(__dirname, '../server-only.js'), |
There was a problem hiding this comment.
The alias points to '../server-only.js' but the actual file is '../server-only.ts'. This will cause module resolution to fail since the .js extension doesn't match the TypeScript source file.
| 'server-only': resolve(__dirname, '../server-only.js'), | |
| 'server-only': resolve(__dirname, '../server-only.ts'), |
| resolve: { | ||
| alias: { | ||
| 'server-only': resolve(__dirname, '../server-only.js'), | ||
| 'client-only': resolve(__dirname, '../client-only.js'), |
There was a problem hiding this comment.
The alias points to '../client-only.js' but the actual file is '../client-only.ts'. This will cause module resolution to fail since the .js extension doesn't match the TypeScript source file.
| 'client-only': resolve(__dirname, '../client-only.js'), | |
| 'client-only': resolve(__dirname, '../client-only.ts'), |
|
|
||
| resolveId(source) { | ||
| if (source === 'server-only') { | ||
| return { id: resolve(__dirname, '../server-only.js'), external: false } |
There was a problem hiding this comment.
The resolveId function points to '../server-only.js' but the actual file is '../server-only.ts'. This will cause module resolution to fail.
| return { id: resolve(__dirname, '../server-only.js'), external: false } | |
| return { id: resolve(__dirname, '../server-only.ts'), external: false } |
| return { id: resolve(__dirname, '../server-only.js'), external: false } | ||
| } | ||
| if (source === 'client-only') { | ||
| return { id: resolve(__dirname, '../client-only.js'), external: false } |
There was a problem hiding this comment.
The resolveId function points to '../client-only.js' but the actual file is '../client-only.ts'. This will cause module resolution to fail.
| return { id: resolve(__dirname, '../client-only.js'), external: false } | |
| return { id: resolve(__dirname, '../client-only.ts'), external: false } |
No description provided.