From 3d901ca59d152ba82fa1471c0e45c9e576f5f864 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Thu, 5 May 2022 15:56:29 -0400 Subject: [PATCH] Revert "refactor: remove serialize-javascript (#3278)" (#3304) * Revert "refactor: remove serialize-javascript (#3278)" This reverts commit 13c1f5ff6bc18f05be2f9fee32331d89fc58af94. * Adds a changeset --- .changeset/sour-pianos-help.md | 5 +++++ packages/astro/package.json | 2 +- packages/astro/src/@types/serialize-javascript.d.ts | 3 +++ packages/astro/src/core/create-vite.ts | 8 ++++++++ packages/astro/src/runtime/server/hydration.ts | 4 ++-- pnpm-lock.yaml | 10 ++-------- 6 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 .changeset/sour-pianos-help.md create mode 100644 packages/astro/src/@types/serialize-javascript.d.ts diff --git a/.changeset/sour-pianos-help.md b/.changeset/sour-pianos-help.md new file mode 100644 index 000000000..459f354b4 --- /dev/null +++ b/.changeset/sour-pianos-help.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes regression that prevented passing classes to islands diff --git a/packages/astro/package.json b/packages/astro/package.json index 103cc9cac..bb1283fde 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -92,7 +92,6 @@ "ci-info": "^3.3.0", "common-ancestor-path": "^1.0.1", "debug": "^4.3.4", - "devalue": "^2.0.1", "diff": "^5.0.0", "eol": "^0.9.1", "es-module-lexer": "^0.10.5", @@ -121,6 +120,7 @@ "resolve": "^1.22.0", "rollup": "^2.70.2", "semver": "^7.3.7", + "serialize-javascript": "^6.0.0", "shiki": "^0.10.1", "sirv": "^2.0.2", "slash": "^4.0.0", diff --git a/packages/astro/src/@types/serialize-javascript.d.ts b/packages/astro/src/@types/serialize-javascript.d.ts new file mode 100644 index 000000000..35ee081b2 --- /dev/null +++ b/packages/astro/src/@types/serialize-javascript.d.ts @@ -0,0 +1,3 @@ +declare module 'serialize-javascript' { + export default function serialize(value: any): string; +} diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts index b793d0e27..728d11d0a 100644 --- a/packages/astro/src/core/create-vite.ts +++ b/packages/astro/src/core/create-vite.ts @@ -21,6 +21,7 @@ const ALWAYS_EXTERNAL = new Set([ ...builtinModules.map((name) => `node:${name}`), '@sveltejs/vite-plugin-svelte', 'micromark-util-events-to-acorn', + 'serialize-javascript', 'node-fetch', 'prismjs', 'shiki', @@ -92,6 +93,13 @@ export async function createVite( css: { postcss: astroConfig.style.postcss || {}, }, + resolve: { + alias: { + // This is needed for Deno compatibility, as the non-browser version + // of this module depends on Node `crypto` + randombytes: 'randombytes/browser', + }, + }, // Note: SSR API is in beta (https://vitejs.dev/guide/ssr.html) ssr: { external: [...ALWAYS_EXTERNAL], diff --git a/packages/astro/src/runtime/server/hydration.ts b/packages/astro/src/runtime/server/hydration.ts index bfb7245da..e7267fe16 100644 --- a/packages/astro/src/runtime/server/hydration.ts +++ b/packages/astro/src/runtime/server/hydration.ts @@ -1,12 +1,12 @@ import type { AstroComponentMetadata, SSRLoadedRenderer } from '../../@types/astro'; import type { SSRElement, SSRResult } from '../../@types/astro'; import { hydrationSpecifier, serializeListValue } from './util.js'; -import devalue from 'devalue'; +import serializeJavaScript from 'serialize-javascript'; // Serializes props passed into a component so that they can be reused during hydration. // The value is any export function serializeProps(value: any) { - return devalue(value); + return serializeJavaScript(value); } const HydrationDirectives = ['load', 'idle', 'media', 'visible', 'only']; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3a0170df1..8eddf9869 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -498,7 +498,6 @@ importers: ci-info: ^3.3.0 common-ancestor-path: ^1.0.1 debug: ^4.3.4 - devalue: ^2.0.1 diff: ^5.0.0 eol: ^0.9.1 es-module-lexer: ^0.10.5 @@ -529,6 +528,7 @@ importers: rollup: ^2.70.2 sass: ^1.50.1 semver: ^7.3.7 + serialize-javascript: ^6.0.0 shiki: ^0.10.1 sirv: ^2.0.2 slash: ^4.0.0 @@ -559,7 +559,6 @@ importers: ci-info: 3.3.0 common-ancestor-path: 1.0.1 debug: 4.3.4 - devalue: 2.0.1 diff: 5.0.0 eol: 0.9.1 es-module-lexer: 0.10.5 @@ -588,6 +587,7 @@ importers: resolve: 1.22.0 rollup: 2.70.2 semver: 7.3.7 + serialize-javascript: 6.0.0 shiki: 0.10.1 sirv: 2.0.2 slash: 4.0.0 @@ -5543,10 +5543,6 @@ packages: defined: 1.0.0 minimist: 1.2.6 - /devalue/2.0.1: - resolution: {integrity: sha512-I2TiqT5iWBEyB8GRfTDP0hiLZ0YeDJZ+upDxjBfOC2lebO5LezQMv7QvIUTzdb64jQyAKLf1AHADtGN+jw6v8Q==} - dev: false - /didyoumean/1.2.2: resolution: {integrity: sha512-gxtyfqMg7GKyhQmb056K7M3xszy/myH8w+B4RT+QXBQsvAOdc3XymqDDPHx1BgPgsdAA5SIifona89YtRATDzw==} @@ -8753,7 +8749,6 @@ packages: resolution: {integrity: sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==} dependencies: safe-buffer: 5.2.1 - dev: true /raw-body/2.5.1: resolution: {integrity: sha512-qqJBtEyVgS0ZmPGdCFPWJ3FreoqvG4MVQln/kCgF7Olq95IbOp0/BWyMwbdtn4VTvkM8Y7khCQ2Xgk/tcrCXig==} @@ -9252,7 +9247,6 @@ packages: resolution: {integrity: sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==} dependencies: randombytes: 2.1.0 - dev: true /set-blocking/2.0.0: resolution: {integrity: sha1-BF+XgtARrppoA93TgrJDkrPYkPc=}