-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat: Add CSP support for hydratable
#17338
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
base: main
Are you sure you want to change the base?
feat: Add CSP support for hydratable
#17338
Conversation
|
|
| body | ||
| body, | ||
| hashes: { | ||
| script: renderer.global.csp.script_hashes |
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.
as of now, this will only ever have one hash in it -- however, with streaming, it would be more...
Thinking ahead, with streaming, this should probably error if you try to access it prior to fully-reading tail, because it needs to be fully-populated before you send the response.
| { | ||
| ${prelude} | ||
| const body = ` | ||
| { |
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.
I dedented and changed the formatting of this stuff because it was confusing in the browser... I could be convinced to sacrifice browser readability for code readability but I don't think the readability here is that bad, and it also technically reduces the byte count
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.
Do you think we should look into some sort of minification in production?
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.
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.
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.
Ah, it's about whether you're viewing source or inspecting
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.
Even when viewing source that seems wrong -- we don't send formatted HTML so it's like... indenting the tags but not the content? Weird
| export async function sha256(data) { | ||
| text_encoder ??= new TextEncoder(); | ||
| // @ts-ignore - we don't install node types in the prod build | ||
| crypto ??= (await import('node:crypto')).webcrypto; |
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.
come to think of it didn't we talk about skipping this and assuming that crypto is always available as a global, given that hydratable is behind the experimental.async flag? not worried about excluding people who want to use bleeding edge Svelte features but are still rocking Node 16 or whatever
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.
The workaround to make it work with the Node 18 tests is just way more annoying than doing this for now 😆 given it won't even run with the above change I'm inclined to just leave it
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.
Can't we just do globalThis.crypto ??= await import('node:crypto').webcrypto in the tests, before this module is imported?
| if (options.csp) { | ||
| csp = | ||
| 'nonce' in options.csp | ||
| ? { nonce: options.csp.nonce, hash: false } | ||
| : { hash: options.csp.hash, nonce: undefined }; |
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.
can't we just use options.csp directly?
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.
Not as currently typed -- the input value is a union. Maybe this is undesirable and we should just use an object with optional keys and JSDoc?
| { | ||
| ${prelude} | ||
| const body = ` | ||
| { |
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.
Co-authored-by: Rich Harris <[email protected]>



This also gives us an avenue for supporting CSS stuff in the future.
Before submitting the PR, please make sure you do the following
feat:,fix:,chore:, ordocs:.packages/svelte/src, add a changeset (npx changeset).Tests and linting
pnpm testand lint the project withpnpm lint