-
Notifications
You must be signed in to change notification settings - Fork 408
Improve DX and test-cases on seroval mode #2073
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
aba4975
add a fixture for more easily test Seroval modes / add JSDoc for config
atilafassina 3437612
update the JSDoc description to include CSP
atilafassina 8137b52
fix package name
atilafassina be9828c
remove middelware from e2e. It's not used.
atilafassina 209d950
typo
atilafassina a67d832
remaining dead code... bye
atilafassina 950405a
remove more useless code
atilafassina 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,19 @@ | ||
| # Serialization checks | ||
|
|
||
| This fixture is designed to point out the differences between Seroval 2 modes. | ||
|
|
||
| ```ts | ||
| export default defineConfig({ | ||
| middleware: "./src/middleware.ts", | ||
| serialization: { | ||
| mode: "js" // "json" | ||
| } | ||
| }); | ||
| ``` | ||
|
|
||
| On JS mode, seroval will use a custom serializer, while this improves performance and reduces payload size, it runs an `eval()` on client-side, | ||
| so a strict CSP will block deserialization. On JSON mode, the payload will be slightly larger, but deserialization happens via `JSON.parse` and thus CSP will not block it. | ||
|
|
||
| > [!IMPORTANT] | ||
| > For backwards compatibility, `v1` has "js" as the default. | ||
| > On `v2`, "json" is the new default. |
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,8 @@ | ||
| import { defineConfig } from "@solidjs/start/config"; | ||
|
|
||
| export default defineConfig({ | ||
| middleware: "./src/middleware.ts", | ||
| serialization: { | ||
| mode: "js" | ||
| } | ||
| }); |
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,21 @@ | ||
| { | ||
| "name": "fixture-serialization-modes", | ||
| "type": "module", | ||
| "scripts": { | ||
| "dev": "vinxi dev", | ||
| "build": "vinxi build", | ||
| "start": "vinxi start", | ||
| "version": "vinxi version" | ||
| }, | ||
| "dependencies": { | ||
| "@solidjs/meta": "^0.29.4", | ||
| "@solidjs/router": "^0.15.0", | ||
| "@solidjs/start": "workspace:*", | ||
| "shieldwall": "^0.4.0", | ||
| "solid-js": "^1.9.5", | ||
| "vinxi": "^0.5.7" | ||
| }, | ||
| "engines": { | ||
| "node": ">=22" | ||
| } | ||
| } |
Binary file not shown.
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,39 @@ | ||
| body { | ||
| font-family: Gordita, Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif; | ||
| } | ||
|
|
||
| a { | ||
| margin-right: 1rem; | ||
| } | ||
|
|
||
| main { | ||
| text-align: center; | ||
| padding: 1em; | ||
| margin: 0 auto; | ||
| } | ||
|
|
||
| h1 { | ||
| color: #335d92; | ||
| text-transform: uppercase; | ||
| font-size: 4rem; | ||
| font-weight: 100; | ||
| line-height: 1.1; | ||
| margin: 4rem auto; | ||
| max-width: 14rem; | ||
| } | ||
|
|
||
| p { | ||
| max-width: 14rem; | ||
| margin: 2rem auto; | ||
| line-height: 1.35; | ||
| } | ||
|
|
||
| @media (min-width: 480px) { | ||
| h1 { | ||
| max-width: none; | ||
| } | ||
|
|
||
| p { | ||
| max-width: none; | ||
| } | ||
| } |
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,22 @@ | ||
| import { MetaProvider, Title } from "@solidjs/meta"; | ||
| import { Router } from "@solidjs/router"; | ||
| import { FileRoutes } from "@solidjs/start/router"; | ||
| import { Suspense } from "solid-js"; | ||
| import "./app.css"; | ||
|
|
||
| export default function App() { | ||
| return ( | ||
| <Router | ||
| root={props => ( | ||
| <MetaProvider> | ||
| <Title>SolidStart - Basic</Title> | ||
| <a href="/">Index</a> | ||
| <a href="/about">About</a> | ||
| <Suspense>{props.children}</Suspense> | ||
| </MetaProvider> | ||
| )} | ||
| > | ||
| <FileRoutes /> | ||
| </Router> | ||
| ); | ||
| } |
21 changes: 21 additions & 0 deletions
21
apps/fixtures/serialization-modes/src/components/Counter.css
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,21 @@ | ||
| .increment { | ||
| font-family: inherit; | ||
| font-size: inherit; | ||
| padding: 1em 2em; | ||
| color: #335d92; | ||
| background-color: rgba(68, 107, 158, 0.1); | ||
| border-radius: 2em; | ||
| border: 2px solid rgba(68, 107, 158, 0); | ||
| outline: none; | ||
| width: 200px; | ||
| font-variant-numeric: tabular-nums; | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| .increment:focus { | ||
| border: 2px solid #335d92; | ||
| } | ||
|
|
||
| .increment:active { | ||
| background-color: rgba(68, 107, 158, 0.2); | ||
| } |
11 changes: 11 additions & 0 deletions
11
apps/fixtures/serialization-modes/src/components/Counter.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,11 @@ | ||
| import { createSignal } from "solid-js"; | ||
| import "./Counter.css"; | ||
|
|
||
| export default function Counter() { | ||
| const [count, setCount] = createSignal(0); | ||
| return ( | ||
| <button class="increment" onClick={() => setCount(count() + 1)} type="button"> | ||
| Clicks: {count()} | ||
| </button> | ||
| ); | ||
| } |
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,4 @@ | ||
| // @refresh reload | ||
| import { mount, StartClient } from "@solidjs/start/client"; | ||
|
|
||
| mount(() => <StartClient />, document.getElementById("app")!); |
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,21 @@ | ||
| // @refresh reload | ||
| import { createHandler, StartServer } from "@solidjs/start/server"; | ||
|
|
||
| export default createHandler(() => ( | ||
| <StartServer | ||
| document={({ assets, children, scripts }) => ( | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
| <link rel="icon" href="/favicon.ico" /> | ||
| {assets} | ||
| </head> | ||
| <body> | ||
| <div id="app">{children}</div> | ||
| {scripts} | ||
| </body> | ||
| </html> | ||
| )} | ||
| /> | ||
| )); |
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 @@ | ||
| /// <reference types="@solidjs/start/env" /> |
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 @@ | ||
| import { createMiddleware } from "@solidjs/start/middleware"; | ||
| import { csp } from "shieldwall/start"; | ||
| import { UNSAFE_INLINE } from "shieldwall/start/csp"; | ||
|
|
||
| export default createMiddleware({ | ||
| onRequest: [ | ||
| csp({ | ||
| extend: "production_basic", | ||
| config: { | ||
| withNonce: false, | ||
| reportOnly: false, | ||
| value: { | ||
| "default-src": ["self"], | ||
| "script-src": ["self", UNSAFE_INLINE, "http:"], | ||
| "style-src": ["self", UNSAFE_INLINE], | ||
| "img-src": ["self", "data:", "https:", "http:"], | ||
| "font-src": ["self"], | ||
| "connect-src": ["self", "ws://localhost:*", "http://localhost:*"], | ||
| "frame-src": ["self"], | ||
| "base-uri": ["self"] | ||
| // "form-action": ["self"] | ||
| } | ||
| } | ||
| }) | ||
| ] | ||
| }); | ||
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 { Title } from "@solidjs/meta"; | ||
| import { HttpStatusCode } from "@solidjs/start"; | ||
|
|
||
| export default function NotFound() { | ||
| return ( | ||
| <main> | ||
| <Title>Not Found</Title> | ||
| <HttpStatusCode code={404} /> | ||
| <h1>Page Not Found</h1> | ||
| <p> | ||
| Visit{" "} | ||
| <a href="https://start.solidjs.com" target="_blank"> | ||
| start.solidjs.com | ||
| </a>{" "} | ||
| to learn how to build SolidStart apps. | ||
| </p> | ||
| </main> | ||
| ); | ||
| } |
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,30 @@ | ||
| import { Title } from "@solidjs/meta"; | ||
| import { createEffect } from "solid-js"; | ||
| import Counter from "~/components/Counter"; | ||
|
|
||
| const breakval = () => { | ||
| "use server"; | ||
|
|
||
| return new Date(); | ||
| }; | ||
|
|
||
| export default function Home() { | ||
| createEffect(() => { | ||
| console.log(breakval()); | ||
atilafassina marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| return ( | ||
| <main> | ||
| <Title>Hello World</Title> | ||
| <h1>Hello world!</h1> | ||
| <Counter /> | ||
| <p> | ||
| Visit{" "} | ||
| <a href="https://start.solidjs.com" target="_blank"> | ||
| start.solidjs.com | ||
| </a>{" "} | ||
| to learn how to build SolidStart apps. | ||
| </p> | ||
| </main> | ||
| ); | ||
| } | ||
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 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "target": "ESNext", | ||
| "module": "ESNext", | ||
| "moduleResolution": "bundler", | ||
| "allowSyntheticDefaultImports": true, | ||
| "esModuleInterop": true, | ||
| "jsx": "preserve", | ||
| "jsxImportSource": "solid-js", | ||
| "allowJs": true, | ||
| "strict": true, | ||
| "noEmit": true, | ||
| "types": ["vinxi/types/client"], | ||
| "isolatedModules": true, | ||
| "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,5 @@ | ||
| import { createMiddleware } from "@solidjs/start/middleware"; | ||
|
|
||
| export default createMiddleware({ | ||
| onRequest: [] | ||
| }); |
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,23 @@ | ||
| import { Title } from "@solidjs/meta"; | ||
| import { action, useSubmission } from "@solidjs/router"; | ||
| import { Show } from "solid-js"; | ||
|
|
||
| const actionStuff = action(async () => { | ||
| "use server"; | ||
|
|
||
| return "Hello world!"; | ||
| }, "actionStuff"); | ||
|
|
||
| export default function Home() { | ||
| const actionData = useSubmission(actionStuff); | ||
| return ( | ||
| <main> | ||
| <Title>Hello World</Title> | ||
| <form action={actionStuff} method="post"> | ||
| <button type="submit">Click me</button> | ||
| </form> | ||
|
|
||
| <Show when={actionData}>{result => <p>{result().result}</p>}</Show> | ||
| </main> | ||
| ); | ||
| } |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.