From 1c2d6e4e29686fee8442f6b92aa6f9ad2e2fc980 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 18 Oct 2022 12:19:08 +0100 Subject: [PATCH 1/4] chore: add start command for stackblitz codeflow (#8279) --- .stackblitz/config.json | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .stackblitz/config.json diff --git a/.stackblitz/config.json b/.stackblitz/config.json new file mode 100644 index 00000000000..41af21c43bc --- /dev/null +++ b/.stackblitz/config.json @@ -0,0 +1,3 @@ +{ + "startCommand": "pnpm build:stub && pnpm play" +} From cfaa46201ac284ea4bd2d8f8ba35d48d82156276 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Tue, 18 Oct 2022 17:13:50 +0100 Subject: [PATCH 2/4] fix(nuxt): lazy-load entry CSS (#8278) --- packages/nuxt/src/core/runtime/nitro/renderer.ts | 13 +++++++++++-- packages/nuxt/src/core/templates.ts | 7 +++++-- packages/vite/src/server.ts | 4 ++-- test/basic.test.ts | 3 +-- .../extends/node_modules/foo/server/api/foo.ts | 4 +++- .../node_modules/foo/server/middleware/foo.ts | 6 ++++-- 6 files changed, 26 insertions(+), 11 deletions(-) diff --git a/packages/nuxt/src/core/runtime/nitro/renderer.ts b/packages/nuxt/src/core/runtime/nitro/renderer.ts index 24199f51e8e..ceff0fd6257 100644 --- a/packages/nuxt/src/core/runtime/nitro/renderer.ts +++ b/packages/nuxt/src/core/runtime/nitro/renderer.ts @@ -10,7 +10,12 @@ import { useRuntimeConfig, useNitroApp, defineRenderHandler, getRouteRules } fro import type { NuxtApp, NuxtSSRContext } from '#app' // @ts-ignore -import { buildAssetsURL } from '#paths' +import { buildAssetsURL, publicAssetsURL } from '#paths' + +// @ts-ignore +globalThis.__buildAssetsURL = buildAssetsURL +// @ts-ignore +globalThis.__publicAssetsURL = publicAssetsURL export interface NuxtRenderHTMLContext { htmlAttrs: string[] @@ -198,7 +203,7 @@ export default defineRenderHandler(async (event) => { const renderedMeta = await ssrContext.renderMeta?.() ?? {} // Render inline styles - const inlinedStyles = process.env.NUXT_INLINE_STYLES && !(process.env.NUXT_NO_SSR || ssrContext.noSSR) + const inlinedStyles = process.env.NUXT_INLINE_STYLES ? await renderInlineStyles(ssrContext.modules ?? ssrContext._registeredComponents ?? []) : '' @@ -284,6 +289,7 @@ function renderHTMLDocument (html: NuxtRenderHTMLContext) { } async function renderInlineStyles (usedModules: Set | string[]) { + const { entryCSS } = await getClientManifest() const styleMap = await getSSRStyles() const inlinedStyles = new Set() for (const mod of ['entry', ...usedModules]) { @@ -293,6 +299,9 @@ async function renderInlineStyles (usedModules: Set | string[]) { } } } + for (const css of entryCSS?.css || []) { + inlinedStyles.add(``) + } return Array.from(inlinedStyles).join('') } diff --git a/packages/nuxt/src/core/templates.ts b/packages/nuxt/src/core/templates.ts index 4aa110f9124..76d914672d6 100644 --- a/packages/nuxt/src/core/templates.ts +++ b/packages/nuxt/src/core/templates.ts @@ -240,8 +240,11 @@ export const publicPathTemplate: NuxtTemplate = { ' return path.length ? joinURL(publicBase, ...path) : publicBase', '}', - 'globalThis.__buildAssetsURL = buildAssetsURL', - 'globalThis.__publicAssetsURL = publicAssetsURL' + // On server these are registered directly in packages/nuxt/src/core/runtime/nitro/renderer.ts + 'if (process.client) {', + ' globalThis.__buildAssetsURL = buildAssetsURL', + ' globalThis.__publicAssetsURL = publicAssetsURL', + '}' ].filter(Boolean).join('\n') } } diff --git a/packages/vite/src/server.ts b/packages/vite/src/server.ts index fe99919aa2e..66b0b9b47db 100644 --- a/packages/vite/src/server.ts +++ b/packages/vite/src/server.ts @@ -129,13 +129,13 @@ export async function buildServer (ctx: ViteBuildContext) { } // Add entry CSS as prefetch (non-blocking) if (entry.isEntry) { - manifest[key + '-css'] = { + manifest.entryCSS = { file: '', css: entry.css } entry.css = [] entry.dynamicImports = entry.dynamicImports || [] - entry.dynamicImports.push(key + '-css') + entry.dynamicImports.push('entryCSS') } } }) diff --git a/test/basic.test.ts b/test/basic.test.ts index 2c22c0cab86..7d95f6712c1 100644 --- a/test/basic.test.ts +++ b/test/basic.test.ts @@ -616,8 +616,7 @@ describe.skipIf(process.env.NUXT_TEST_DEV || process.env.TEST_WITH_WEBPACK)('inl `) }) - // TODO: fix this in style inlining implementation: https://github.com/nuxt/framework/pull/8265#issuecomment-1282148407 - it.skip('still downloads client-only styles', async () => { + it('still downloads client-only styles', async () => { const page = await createPage('/styles') await page.waitForLoadState('networkidle') expect(await page.$eval('.client-only-css', e => getComputedStyle(e).color)).toBe('rgb(50, 50, 50)') diff --git a/test/fixtures/basic/extends/node_modules/foo/server/api/foo.ts b/test/fixtures/basic/extends/node_modules/foo/server/api/foo.ts index f759e165008..4529f026397 100644 --- a/test/fixtures/basic/extends/node_modules/foo/server/api/foo.ts +++ b/test/fixtures/basic/extends/node_modules/foo/server/api/foo.ts @@ -1 +1,3 @@ -export default () => 'foo' +import { eventHandler } from 'h3' + +export default eventHandler(() => 'foo') diff --git a/test/fixtures/basic/extends/node_modules/foo/server/middleware/foo.ts b/test/fixtures/basic/extends/node_modules/foo/server/middleware/foo.ts index 0af570f235f..aedbcc3fbf4 100644 --- a/test/fixtures/basic/extends/node_modules/foo/server/middleware/foo.ts +++ b/test/fixtures/basic/extends/node_modules/foo/server/middleware/foo.ts @@ -1,4 +1,6 @@ // TODO: add back TypeScript and auto-importing once Nitro supports it -export default (event) => { +import { eventHandler } from 'h3' + +export default eventHandler((event) => { event.res.setHeader('injected-header', 'foo') -} +}) From c6a6dceec110548cf27fd602a7f5cfe98bb23e7e Mon Sep 17 00:00:00 2001 From: Anish Ghimire Date: Tue, 18 Oct 2022 21:59:12 +0545 Subject: [PATCH 3/4] docs: add cleavr to supported hosting providers (#8285) --- docs/content/1.getting-started/10.deployment.md | 1 + docs/public/_redirects | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/content/1.getting-started/10.deployment.md b/docs/content/1.getting-started/10.deployment.md index 435f0fcdff7..d7f2af80792 100644 --- a/docs/content/1.getting-started/10.deployment.md +++ b/docs/content/1.getting-started/10.deployment.md @@ -139,6 +139,7 @@ Nuxt 3 can be deployed to several cloud providers with a minimal amount of confi - :IconCloud{class="h-5 w-4 inline mb-2"} [AWS](https://nitro.unjs.io/deploy/providers/aws) - :LogoAzure{class="h-5 w-4 inline mb-2"} [Azure](https://nitro.unjs.io/deploy/providers/azure) +- :IconCloud{class="h-5 w-4 inline mb-2"} [Cleavr](https://nitro.unjs.io/deploy/providers/cleavr) - :LogoCloudFlare{class="h-5 w-4 inline mb-2"} [CloudFlare](https://nitro.unjs.io/deploy/providers/cloudflare) - :IconCloud{class="h-5 w-4 inline mb-2"} [Digital Ocean](https://nitro.unjs.io/deploy/providers/digitalocean) - :LogoFirebase{class="h-5 w-4 inline mb-2"} [Firebase](https://nitro.unjs.io/deploy/providers/firebase) diff --git a/docs/public/_redirects b/docs/public/_redirects index d3743bf79a9..bcf4ce6f6be 100644 --- a/docs/public/_redirects +++ b/docs/public/_redirects @@ -74,4 +74,5 @@ /guide/deploy/providers/render https://nitro.unjs.io/deploy/providers/render 302! /guide/deploy/providers/stormkit https://nitro.unjs.io/deploy/providers/stormkit 302! /guide/deploy/providers/vercel https://nitro.unjs.io/deploy/providers/vercel 302! +/guide/deploy/providers/cleavr https://nitro.unjs.io/deploy/providers/cleavr 302! From e0d6812b6662d71f0ba43e0a0458e39c589b12c2 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 18 Oct 2022 18:14:29 +0200 Subject: [PATCH 4/4] chore(deps): update all non-major dependencies (#8286) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 2 +- packages/nuxi/package.json | 2 +- packages/nuxt/package.json | 4 ++-- packages/schema/package.json | 2 +- packages/vite/package.json | 2 +- pnpm-lock.yaml | 40 ++++++++++++++++++++---------------- 6 files changed, 28 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index 90b38586453..bf359015664 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "@types/node": "^16.11.66", "@types/rimraf": "^3", "@types/semver": "^7", - "@unocss/reset": "^0.45.29", + "@unocss/reset": "^0.45.30", "case-police": "^0.5.10", "changelogen": "^0.3.5", "crawler": "^1.3.0", diff --git a/packages/nuxi/package.json b/packages/nuxi/package.json index dbeb3f7aafa..50d54bbdecb 100644 --- a/packages/nuxi/package.json +++ b/packages/nuxi/package.json @@ -35,7 +35,7 @@ "execa": "^6.1.0", "flat": "^5.0.2", "giget": "^0.1.7", - "h3": "^0.8.3", + "h3": "^0.8.4", "jiti": "^1.16.0", "listhen": "^0.3.4", "mlly": "^0.5.16", diff --git a/packages/nuxt/package.json b/packages/nuxt/package.json index 15d3a5bf323..c838ae1e49c 100644 --- a/packages/nuxt/package.json +++ b/packages/nuxt/package.json @@ -52,13 +52,13 @@ "escape-string-regexp": "^5.0.0", "fs-extra": "^10.1.0", "globby": "^13.1.2", - "h3": "^0.8.3", + "h3": "^0.8.4", "hash-sum": "^2.0.0", "hookable": "^5.4.1", "knitwork": "^0.1.2", "magic-string": "^0.26.7", "mlly": "^0.5.16", - "nitropack": "npm:nitropack-edge@0.6.0-27767213.0be380d", + "nitropack": "npm:nitropack-edge@0.6.0-27768225.ba21751", "nuxi": "3.0.0-rc.11", "ohash": "^0.1.5", "ohmyfetch": "^0.4.20", diff --git a/packages/schema/package.json b/packages/schema/package.json index 0b4c62e5fb7..95e87a7601b 100644 --- a/packages/schema/package.json +++ b/packages/schema/package.json @@ -18,7 +18,7 @@ "@types/semver": "^7", "@vitejs/plugin-vue": "^3.1.2", "@vueuse/head": "~1.0.0-rc.9", - "nitropack": "npm:nitropack-edge@0.6.0-27767213.0be380d", + "nitropack": "npm:nitropack-edge@0.6.0-27768225.ba21751", "unbuild": "latest", "vite": "~3.1.8" }, diff --git a/packages/vite/package.json b/packages/vite/package.json index 1f9f2657e25..82a7f6dc9b0 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -33,7 +33,7 @@ "externality": "^0.2.2", "fs-extra": "^10.1.0", "get-port-please": "^2.6.1", - "h3": "^0.8.3", + "h3": "^0.8.4", "knitwork": "^0.1.2", "magic-string": "^0.26.7", "mlly": "^0.5.16", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2510421085d..519b398479d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -28,7 +28,7 @@ importers: '@types/node': ^16.11.66 '@types/rimraf': ^3 '@types/semver': ^7 - '@unocss/reset': ^0.45.29 + '@unocss/reset': ^0.45.30 case-police: ^0.5.10 changelogen: ^0.3.5 crawler: ^1.3.0 @@ -64,7 +64,7 @@ importers: '@types/node': 16.11.66 '@types/rimraf': 3.0.2 '@types/semver': 7.3.12 - '@unocss/reset': 0.45.29 + '@unocss/reset': 0.45.30 case-police: 0.5.10 changelogen: 0.3.5 crawler: 1.3.0 @@ -360,7 +360,7 @@ importers: flat: ^5.0.2 fsevents: ~2.3.2 giget: ^0.1.7 - h3: ^0.8.3 + h3: ^0.8.4 jiti: ^1.16.0 listhen: ^0.3.4 mlly: ^0.5.16 @@ -391,7 +391,7 @@ importers: execa: 6.1.0 flat: 5.0.2 giget: 0.1.7 - h3: 0.8.3 + h3: 0.8.4 jiti: 1.16.0 listhen: 0.3.4 mlly: 0.5.16 @@ -423,13 +423,13 @@ importers: escape-string-regexp: ^5.0.0 fs-extra: ^10.1.0 globby: ^13.1.2 - h3: ^0.8.3 + h3: ^0.8.4 hash-sum: ^2.0.0 hookable: ^5.4.1 knitwork: ^0.1.2 magic-string: ^0.26.7 mlly: ^0.5.16 - nitropack: npm:nitropack-edge@0.6.0-27767213.0be380d + nitropack: npm:nitropack-edge@0.6.0-27768225.ba21751 nuxi: workspace:* ohash: ^0.1.5 ohmyfetch: ^0.4.20 @@ -467,13 +467,13 @@ importers: escape-string-regexp: 5.0.0 fs-extra: 10.1.0 globby: 13.1.2 - h3: 0.8.3 + h3: 0.8.4 hash-sum: 2.0.0 hookable: 5.4.1 knitwork: 0.1.2 magic-string: 0.26.7 mlly: 0.5.16 - nitropack: /nitropack-edge/0.6.0-27767213.0be380d + nitropack: /nitropack-edge/0.6.0-27768225.ba21751 nuxi: link:../nuxi ohash: 0.1.5 ohmyfetch: 0.4.20 @@ -508,7 +508,7 @@ importers: create-require: ^1.1.1 defu: ^6.1.0 jiti: ^1.16.0 - nitropack: npm:nitropack-edge@0.6.0-27767213.0be380d + nitropack: npm:nitropack-edge@0.6.0-27768225.ba21751 pathe: ^0.3.9 pkg-types: ^0.3.5 postcss-import-resolver: ^2.0.0 @@ -537,7 +537,7 @@ importers: '@types/semver': 7.3.12 '@vitejs/plugin-vue': 3.1.2_vite@3.1.8 '@vueuse/head': 1.0.0-rc.9 - nitropack: /nitropack-edge/0.6.0-27767213.0be380d + nitropack: /nitropack-edge/0.6.0-27768225.ba21751 unbuild: 0.9.4 vite: 3.1.8 @@ -586,7 +586,7 @@ importers: externality: ^0.2.2 fs-extra: ^10.1.0 get-port-please: ^2.6.1 - h3: ^0.8.3 + h3: ^0.8.4 knitwork: ^0.1.2 magic-string: ^0.26.7 mlly: ^0.5.16 @@ -622,7 +622,7 @@ importers: externality: 0.2.2 fs-extra: 10.1.0 get-port-please: 2.6.1 - h3: 0.8.3 + h3: 0.8.4 knitwork: 0.1.2 magic-string: 0.26.7 mlly: 0.5.16 @@ -2154,6 +2154,10 @@ packages: resolution: {integrity: sha512-ytnKxyJdjvhjHrZ9yQUnQwiuL4hiXvjZUj88F2JkwgFJX6Y8jEz3V2xU1BPZNOv20/F6P1ngzEPRfrWHG8XG6A==} dev: true + /@unocss/reset/0.45.30: + resolution: {integrity: sha512-m6+M3E2cTPhX+2aKocRfDqQt7ebEtjJHH8sVYpX8xJoN0vOqjSNmUYc6AIkwUYljx4QbEC3thcQSbqel82RbXQ==} + dev: true + /@unocss/scope/0.45.25: resolution: {integrity: sha512-ZAQYWfgVhjlswY31f4v7wcQ9PdKLYYHPch3rACPalbPJOc7NVmIWe3gU5H2gUZfeX+SwY9V8zw89DyM8DiRHPw==} dev: true @@ -5408,8 +5412,8 @@ packages: dependencies: duplexer: 0.1.2 - /h3/0.8.3: - resolution: {integrity: sha512-SUTWtkopWX04yzF0YGRwccNpvbRheTkib3PdOsjqx2hBhQcrmljMa28K8dXJd6Kn1LhPia8je093hpRdCObBPg==} + /h3/0.8.4: + resolution: {integrity: sha512-U7ZD/Te+LBS1IpUvsZRe+E+ZiA3zQS0u43DMrZ+raiVObeYe0G5F4Kr/g6Fn2fH92Np0ROkij/wEhkAMbUsBdQ==} dependencies: cookie-es: 0.5.0 destr: 1.1.1 @@ -6449,8 +6453,8 @@ packages: /neo-async/2.6.2: resolution: {integrity: sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==} - /nitropack-edge/0.6.0-27767213.0be380d: - resolution: {integrity: sha512-LDnqyO8+BtFvoYFJKF88REhXaM3mQF6k3qdvOumNJC0uMFmg7mbirTuNTbGf1TAs1Zn2S90T1r+04ZiCTG2vKQ==} + /nitropack-edge/0.6.0-27768225.ba21751: + resolution: {integrity: sha512-XDXE1D4oDuiuqGy578WvWlDT9eQEVVFqaQVEygTcmJahdkW2yWHhBM94xWrvQcw7MUWNzIzF716TK4s5QK13Fw==} engines: {node: ^14.16.0 || ^16.11.0 || ^17.0.0 || ^18.0.0} hasBin: true dependencies: @@ -6480,7 +6484,7 @@ packages: fs-extra: 10.1.0 globby: 13.1.2 gzip-size: 7.0.0 - h3: 0.8.3 + h3: 0.8.4 hookable: 5.4.1 http-proxy: 1.18.1 is-primitive: 3.0.1 @@ -8429,7 +8433,7 @@ packages: anymatch: 3.1.2 chokidar: 3.5.3 destr: 1.1.1 - h3: 0.8.3 + h3: 0.8.4 ioredis: 5.2.3 listhen: 0.3.4 mkdir: 0.0.2