-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: server-only folder and suffix #8605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Varixo
wants to merge
4
commits into
build/v2
Choose a base branch
from
v2-server-only
base: build/v2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@qwik.dev/core': patch | ||
| --- | ||
|
|
||
| feat: reject server-only modules from client builds | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "description": "Server-only modules rejected e2e app", | ||
| "type": "module", | ||
| "__qwik__": { | ||
| "qwikRouter": true | ||
| } | ||
| } |
3 changes: 3 additions & 0 deletions
3
e2e/qwik-e2e/apps/server-only-modules-rejected/src/client-helper.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { loadSecret } from './db.server'; | ||
|
|
||
| export const getClientValue = () => loadSecret(); |
1 change: 1 addition & 0 deletions
1
e2e/qwik-e2e/apps/server-only-modules-rejected/src/db.server.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const loadSecret = () => 'SERVER_ONLY_SECRET'; |
12 changes: 12 additions & 0 deletions
12
e2e/qwik-e2e/apps/server-only-modules-rejected/src/dynamic-import-root.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { component$, useSignal, useVisibleTask$ } from '@qwik.dev/core'; | ||
|
|
||
| export default component$(() => { | ||
| const secret = useSignal(''); | ||
|
|
||
| useVisibleTask$(async () => { | ||
| const module = await import('./db.server'); | ||
| secret.value = module.loadSecret(); | ||
| }); | ||
|
|
||
| return <main>{secret.value}</main>; | ||
| }); |
9 changes: 9 additions & 0 deletions
9
e2e/qwik-e2e/apps/server-only-modules-rejected/src/entry.ssr.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { renderToStream, type RenderToStreamOptions } from '@qwik.dev/core/server'; | ||
| import Root from './root'; | ||
|
|
||
| export default function (opts: RenderToStreamOptions) { | ||
| return renderToStream(<Root />, { | ||
| base: '/server-only-modules-rejected/build/', | ||
| ...opts, | ||
| }); | ||
| } |
3 changes: 3 additions & 0 deletions
3
e2e/qwik-e2e/apps/server-only-modules-rejected/src/folder-client-helper.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { loadFolderSecret } from './server/folder-secret'; | ||
|
|
||
| export const getFolderClientValue = () => loadFolderSecret(); |
3 changes: 3 additions & 0 deletions
3
e2e/qwik-e2e/apps/server-only-modules-rejected/src/re-export-client-helper.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| import { loadReExportedSecret } from './re-exported-secret'; | ||
|
|
||
| export const getReExportedClientValue = () => loadReExportedSecret(); |
6 changes: 6 additions & 0 deletions
6
e2e/qwik-e2e/apps/server-only-modules-rejected/src/re-export-root.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { component$ } from '@qwik.dev/core'; | ||
| import { getReExportedClientValue } from './re-export-client-helper'; | ||
|
|
||
| export default component$(() => { | ||
| return <main>{getReExportedClientValue()}</main>; | ||
| }); |
1 change: 1 addition & 0 deletions
1
e2e/qwik-e2e/apps/server-only-modules-rejected/src/re-exported-secret.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { loadSecret as loadReExportedSecret } from './db.server'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { component$ } from '@qwik.dev/core'; | ||
| import { getClientValue } from './client-helper'; | ||
|
|
||
| export default component$(() => { | ||
| return <main>{getClientValue()}</main>; | ||
| }); |
18 changes: 18 additions & 0 deletions
18
e2e/qwik-e2e/apps/server-only-modules-rejected/src/routes/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import type { DocumentHead } from '@qwik.dev/router'; | ||
| import { component$, useSignal } from '@qwik.dev/core'; | ||
| import { loadSecret } from '../db.server'; | ||
|
|
||
| export default component$(() => { | ||
| const count = useSignal(0); | ||
| return ( | ||
| <main> | ||
| <h1>Hi</h1> | ||
| <button onClick$={() => count.value++}>Increment</button> | ||
| <span>{loadSecret()}</span> | ||
| </main> | ||
| ); | ||
| }); | ||
|
|
||
| export const head: DocumentHead = { | ||
| title: 'Server-only rejected', | ||
| }; |
6 changes: 6 additions & 0 deletions
6
e2e/qwik-e2e/apps/server-only-modules-rejected/src/server-folder-root.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { component$ } from '@qwik.dev/core'; | ||
| import { getFolderClientValue } from './folder-client-helper'; | ||
|
|
||
| export default component$(() => { | ||
| return <main>{getFolderClientValue()}</main>; | ||
| }); |
1 change: 1 addition & 0 deletions
1
e2e/qwik-e2e/apps/server-only-modules-rejected/src/server/folder-secret.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const loadFolderSecret = () => 'SERVER_FOLDER_SECRET'; |
26 changes: 26 additions & 0 deletions
26
e2e/qwik-e2e/apps/server-only-modules-rejected/tsconfig.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "allowJs": true, | ||
| "target": "ES2020", | ||
| "module": "ES2022", | ||
| "lib": ["es2022", "DOM", "WebWorker", "DOM.Iterable"], | ||
| "jsx": "react-jsx", | ||
| "jsxImportSource": "@qwik.dev/core", | ||
| "strict": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "resolveJsonModule": true, | ||
| "moduleResolution": "Bundler", | ||
| "esModuleInterop": true, | ||
| "allowImportingTsExtensions": true, | ||
| "skipLibCheck": true, | ||
| "incremental": true, | ||
| "isolatedModules": true, | ||
| "outDir": "tmp", | ||
| "noEmit": true, | ||
| "types": ["node", "vite/client"], | ||
| "rootDir": ".", | ||
| "paths": { | ||
| "~/*": ["./src/*"] | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "description": "Server-only modules e2e app", | ||
| "type": "module", | ||
| "__qwik__": { | ||
| "qwikRouter": true | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const loadSecret = () => 'SERVER_ONLY_SECRET'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { renderToStream, type RenderToStreamOptions } from '@qwik.dev/core/server'; | ||
| import Root from './root'; | ||
|
|
||
| export default function (opts: RenderToStreamOptions) { | ||
| return renderToStream(<Root />, { | ||
| base: '/server-only-modules/build/', | ||
| ...opts, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { component$ } from '@qwik.dev/core'; | ||
| import { RouterOutlet, useQwikRouter } from '@qwik.dev/router'; | ||
|
|
||
| export default component$(() => { | ||
| useQwikRouter(); | ||
|
|
||
| return ( | ||
| <body> | ||
| <RouterOutlet /> | ||
| </body> | ||
| ); | ||
| }); |
19 changes: 19 additions & 0 deletions
19
e2e/qwik-e2e/apps/server-only-modules/src/routes/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { component$ } from '@qwik.dev/core'; | ||
| import { routeLoader$ } from '@qwik.dev/router'; | ||
| import { loadSecret } from '../db.server'; | ||
| import { loadFolderSecret } from '../server/folder-secret'; | ||
|
|
||
| export const useSecret = routeLoader$(() => { | ||
| return `${loadSecret()} ${loadFolderSecret()}`; | ||
| }); | ||
|
|
||
| export default component$(() => { | ||
| const secret = useSecret(); | ||
| const exampleText = "import './fake.server'"; | ||
| return ( | ||
| <main> | ||
| {secret.value} | ||
| <code>{exampleText}</code> | ||
| </main> | ||
| ); | ||
| }); |
1 change: 1 addition & 0 deletions
1
e2e/qwik-e2e/apps/server-only-modules/src/server/folder-secret.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const loadFolderSecret = () => 'SERVER_FOLDER_SECRET'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "allowJs": true, | ||
| "target": "ES2020", | ||
| "module": "ES2022", | ||
| "lib": ["es2022", "DOM", "WebWorker", "DOM.Iterable"], | ||
| "jsx": "react-jsx", | ||
| "jsxImportSource": "@qwik.dev/core", | ||
| "strict": true, | ||
| "forceConsistentCasingInFileNames": true, | ||
| "resolveJsonModule": true, | ||
| "moduleResolution": "Bundler", | ||
| "esModuleInterop": true, | ||
| "allowImportingTsExtensions": true, | ||
| "skipLibCheck": true, | ||
| "incremental": true, | ||
| "isolatedModules": true, | ||
| "outDir": "tmp", | ||
| "noEmit": true, | ||
| "types": ["node", "vite/client"], | ||
| "rootDir": ".", | ||
| "paths": { | ||
| "~/*": ["./src/*"] | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be major as it can break when people use .server in their project