diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 337bde873..2f98bf80f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,7 +83,7 @@ jobs: run: pnpm install - name: Initialize CodeQL - uses: github/codeql-action/init@9fdb3e49720b44c48891d036bb502feb25684276 # v3.25.6 + uses: github/codeql-action/init@2e230e8fe0ad3a14a340ad0815ddb96d599d2aff # v3.25.8 with: languages: javascript queries: +security-and-quality @@ -95,7 +95,7 @@ jobs: path: packages - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@9fdb3e49720b44c48891d036bb502feb25684276 # v3.25.6 + uses: github/codeql-action/analyze@2e230e8fe0ad3a14a340ad0815ddb96d599d2aff # v3.25.8 with: category: "/language:javascript" diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml index 62daccd7f..7c6cfb674 100644 --- a/.github/workflows/dependency-review.yml +++ b/.github/workflows/dependency-review.yml @@ -19,4 +19,4 @@ jobs: - name: 'Checkout Repository' uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 - name: 'Dependency Review' - uses: actions/dependency-review-action@0c155c5e8556a497adf53f2c18edabf945ed8e70 # v4.3.2 + uses: actions/dependency-review-action@72eb03d02c7872a771aacd928f3123ac62ad6d3a # v4.3.3 diff --git a/.github/workflows/nuxt2-edge.yml b/.github/workflows/nuxt2-edge.yml deleted file mode 100644 index 0b12d5c63..000000000 --- a/.github/workflows/nuxt2-edge.yml +++ /dev/null @@ -1,61 +0,0 @@ -name: nuxt2-nightly - -on: - workflow_dispatch: - schedule: - - cron: '0 0 * * *' - -# https://github.com/vitejs/vite/blob/main/.github/workflows/ci.yml -env: - # 7 GiB by default on GitHub, setting to 6 GiB - # https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources - NODE_OPTIONS: --max-old-space-size=6144 - -permissions: - contents: read - -jobs: - nightly: - if: github.repository_owner == 'nuxt' - runs-on: ubuntu-latest - permissions: - id-token: write - steps: - - uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 - with: - ref: '2.x' - fetch-depth: 0 # All history - - name: fetch tags - run: git fetch --depth=1 origin "+refs/tags/*:refs/tags/*" - - uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2 - with: - node-version: 18 - registry-url: 'https://registry.npmjs.org' - - name: install - run: yarn --check-files --frozen-lockfile --non-interactive - - name: lint - run: yarn test:lint - - name: audit - run: yarn run audit - - name: build - run: yarn test:fixtures -i - - name: lint app - run: yarn lint:app - - name: test types - run: yarn test:types - - name: test dev - run: yarn test:dev - - name: test unit - run: yarn test:unit - - name: test e2e - run: yarn test:e2e - - name: bump version - run: yarn lerna version --yes --no-changelog --no-git-tag-version --no-push --force-publish "*" --loglevel verbose - - name: build - run: PACKAGE_SUFFIX=edge yarn build - - name: publish - run: ./scripts/workspace-run npm publish -q - env: - NODE_AUTH_TOKEN: ${{secrets.NODE_AUTH_TOKEN}} - NPM_CONFIG_PROVENANCE: true - diff --git a/.github/workflows/scorecards.yml b/.github/workflows/scorecards.yml index 1a0a7912d..7a36b4a41 100644 --- a/.github/workflows/scorecards.yml +++ b/.github/workflows/scorecards.yml @@ -68,7 +68,7 @@ jobs: # Upload the results to GitHub's code scanning dashboard. - name: "Upload to code-scanning" - uses: github/codeql-action/upload-sarif@9fdb3e49720b44c48891d036bb502feb25684276 # v3.25.6 + uses: github/codeql-action/upload-sarif@2e230e8fe0ad3a14a340ad0815ddb96d599d2aff # v3.25.8 if: github.repository == 'nuxt/nuxt' && success() with: sarif_file: results.sarif diff --git a/docs/1.getting-started/6.data-fetching.md b/docs/1.getting-started/6.data-fetching.md index 32976b1f2..84b36df3b 100644 --- a/docs/1.getting-started/6.data-fetching.md +++ b/docs/1.getting-started/6.data-fetching.md @@ -623,3 +623,37 @@ const { data } = await useFetch('/api/superjson', { }) ``` + +## Recipes + +### Consuming SSE (Server Sent Events) via POST request + +::tip +If you're consuming SSE via GET request, you can use [`EventSource`](https://developer.mozilla.org/en-US/docs/Web/API/EventSource) or VueUse composable [`useEventSource`](https://vueuse.org/core/useEventSource/). +:: + +When consuming SSE via POST request, you need to handle the connection manually. Here's how you can do it: + +```ts +// Make a POST request to the SSE endpoint +const response = await $fetch('/chats/ask-ai', { + method: 'POST', + body: { + query: "Hello AI, how are you?", + }, + responseType: 'stream', +}) + +// Create a new ReadableStream from the response with TextDecoderStream to get the data as text +const reader = response.pipeThrough(new TextDecoderStream()).getReader() + +// Read the chunk of data as we get it +while (true) { + const { value, done } = await reader.read() + + if (done) + break + + console.log('Received:', value) +} +``` diff --git a/docs/2.guide/1.concepts/3.rendering.md b/docs/2.guide/1.concepts/3.rendering.md index 4adf1baaa..8bfe220a3 100644 --- a/docs/2.guide/1.concepts/3.rendering.md +++ b/docs/2.guide/1.concepts/3.rendering.md @@ -69,6 +69,36 @@ If you do use `ssr: false`, you should also place an HTML file in `~/app/spa-loa :read-more{title="SPA Loading Template" to="/docs/api/configuration/nuxt-config#spaloadingtemplate"} :: +::tip{to="https://www.youtube.com/watch?v=7Lr0QTP1Ro8" icon="i-logos-youtube-icon" target="_blank"} +Watch a video from Alexander Lichter about **Building a plain SPA with Nuxt!?**. +:: + +### Deploying a Static Client-Rendered App + +If you deploy your app to [static hosting](/docs/getting-started/deployment#static-hosting) with the `nuxi generate` or `nuxi build --prerender` commands, then by default, Nuxt will render every page as a separate static HTML file. + +If you are using purely client-side rendering, then this might be unnecessary. You might only need a single `index.html` file, plus `200.html` and `404.html` fallbacks, which you can tell your static web host to serve up for all requests. + +In order to achieve this we can change how the routes are prerendered. Just add this to [your hooks](/docs/api/advanced/hooks#nuxt-hooks-build-time) in your `nuxt.config.ts`: + +```ts twoslash [nuxt.config.ts] +export default defineNuxtConfig({ + hooks: { + 'prerender:routes' ({ routes }) { + routes.clear() // Do not generate any routes (except the defaults) + } + }, +}) +``` + +This will produce three files: + +- `index.html` +- `200.html` +- `404.html` + +The `200.html` and `404.html` might be useful for the hosting provider you are using. + ## Hybrid Rendering Hybrid rendering allows different caching rules per route using **Route Rules** and decides how the server should respond to a new request on a given URL. diff --git a/docs/3.api/3.utils/navigate-to.md b/docs/3.api/3.utils/navigate-to.md index 0347308a5..6117a38c5 100644 --- a/docs/3.api/3.utils/navigate-to.md +++ b/docs/3.api/3.utils/navigate-to.md @@ -52,6 +52,18 @@ export default defineNuxtRouteMiddleware((to, from) => { ### External URL +The `external` parameter in `navigateTo` influences how navigating to URLs is handled: + +- **Without `external: true`**: + - Internal URLs navigate as expected. + - External URLs throw an error. + +- **With `external: true`**: + - Internal URLs navigate with a full-page reload. + - External URLs navigate as expected. + +#### Example + ```vue