diff --git a/.changeset/afraid-dingos-sing.md b/.changeset/afraid-dingos-sing.md new file mode 100644 index 0000000000..9ee770fe1c --- /dev/null +++ b/.changeset/afraid-dingos-sing.md @@ -0,0 +1,5 @@ +--- +"@formbricks/js": patch +--- + +Introduce response queue for instant question transitions diff --git a/.github/workflows/nextjs-bundle-analysis.yml b/.github/workflows/nextjs-bundle-analysis.yml index 944c810637..586ebb3edd 100644 --- a/.github/workflows/nextjs-bundle-analysis.yml +++ b/.github/workflows/nextjs-bundle-analysis.yml @@ -1,3 +1,6 @@ +# Copyright (c) HashiCorp, Inc. +# SPDX-License-Identifier: MPL-2.0 + name: "Next.js Bundle Analysis" on: @@ -6,51 +9,59 @@ on: branches: - main -jobs: - build: - name: Production build - if: ${{ github.event_name == 'push' }} - uses: ./.github/workflows/build-production.yml - secrets: inherit +defaults: + run: + # change this if your nextjs app does not live at the root of the repo + working-directory: ./ +permissions: + contents: read # for checkout repository + actions: read # for fetching base branch bundle stats + pull-requests: write # for comments + +jobs: analyze: - needs: build - if: always() runs-on: ubuntu-latest steps: - - name: Checkout repo - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - - name: Setup Node.js 18.x - uses: actions/setup-node@v2 + - name: Install Node.js + uses: actions/setup-node@v3 with: - node-version: 18.x + node-version: 18 - - name: Install pnpm - uses: pnpm/action-setup@v2.2.4 + # If pnpm is used, you need to switch the previous step with the following one. pnpm does not create a package-lock.json + # so the step above will fail to pull dependencies + - uses: pnpm/action-setup@v2 + name: Install pnpm + id: pnpm-install + with: + version: 7 + run_install: true - - name: Install dependencies - run: pnpm install --config.platform=linux --config.architecture=x64 + - name: Restore next build + uses: actions/cache@v3 + id: restore-build-cache + env: + cache-name: cache-next-build + with: + # if you use a custom build directory, replace all instances of `.next` in this file with your build directory + # ex: if your app builds to `dist`, replace `.next` with `dist` + path: apps/web/.next/cache + # change this if you prefer a more strict cache + key: ${{ runner.os }}-build-${{ env.cache-name }} - - name: create .env - run: cp .env.example .env - - - name: Build formbricks-js dependencies + - name: Build next.js app + # change this if your site requires a custom build command run: pnpm build --filter=web... - - name: Upload bundle - uses: actions/upload-artifact@v2 - with: - name: bundle - path: apps/web/.next/analyze/__bundle_analysis.json - + # Here's the first place where next-bundle-analysis' own script is used + # This step pulls the raw bundle stats for the current bundle - name: Analyze bundle - run: | - cd apps/web - npx -p nextjs-bundle-analysis@0.5.0 report + run: npx -p nextjs-bundle-analysis report - name: Upload bundle - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: bundle path: apps/web/.next/analyze/__bundle_analysis.json @@ -59,7 +70,7 @@ jobs: uses: dawidd6/action-download-artifact@v2 if: success() && github.event.number with: - workflow: nextjs-bundle-analysis.yml + workflow: nextjs_bundle_analysis.yml branch: ${{ github.event.pull_request.base.ref }} path: apps/web/.next/analyze/base @@ -78,38 +89,34 @@ jobs: # entry in your package.json file. - name: Compare with base branch bundle if: success() && github.event.number - run: | - cd apps/web - ls -laR .next/analyze/base && npx -p nextjs-bundle-analysis compare + run: ls -laR apps/web/.next/analyze/base && npx -p nextjs-bundle-analysis compare - - name: Get comment body + - name: Get Comment Body id: get-comment-body if: success() && github.event.number + # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings run: | - cd apps/web - body=$(cat .next/analyze/__bundle_analysis_comment.txt) - body="${body//'%'/'%25'}" - body="${body//$'\n'/'%0A'}" - body="${body//$'\r'/'%0D'}" - echo ::set-output name=body::$body + echo "body<> $GITHUB_OUTPUT + echo "$(cat apps/web/.next/analyze/__bundle_analysis_comment.txt)" >> $GITHUB_OUTPUT + echo EOF >> $GITHUB_OUTPUT - name: Find Comment - uses: peter-evans/find-comment@v1 + uses: peter-evans/find-comment@v2 if: success() && github.event.number id: fc with: issue-number: ${{ github.event.number }} - body-includes: "" + body-includes: "" - name: Create Comment - uses: peter-evans/create-or-update-comment@v1.4.4 + uses: peter-evans/create-or-update-comment@v2 if: success() && github.event.number && steps.fc.outputs.comment-id == 0 with: issue-number: ${{ github.event.number }} body: ${{ steps.get-comment-body.outputs.body }} - name: Update Comment - uses: peter-evans/create-or-update-comment@v1.4.4 + uses: peter-evans/create-or-update-comment@v2 if: success() && github.event.number && steps.fc.outputs.comment-id != 0 with: issue-number: ${{ github.event.number }} diff --git a/package.json b/package.json index c708004390..47a81df856 100644 --- a/package.json +++ b/package.json @@ -52,5 +52,11 @@ "engines": { "node": ">=16.0.0" }, - "packageManager": "pnpm@8.1.1" + "packageManager": "pnpm@8.1.1", + "nextBundleAnalysis": { + "budget": 358400, + "budgetPercentIncreaseRed": 20, + "minimumChangeThreshold": 0, + "showDetails": true + } } diff --git a/packages/lib/responseQueue.ts b/packages/lib/responseQueue.ts index bc13d08f45..013094aec2 100644 --- a/packages/lib/responseQueue.ts +++ b/packages/lib/responseQueue.ts @@ -14,6 +14,7 @@ export class ResponseQueue { private queue: TResponseUpdate[] = []; private config: QueueConfig; private surveyState: SurveyState; + private isRequestInProgress = false; constructor(config: QueueConfig, surveyState: SurveyState) { this.config = config; @@ -32,8 +33,11 @@ export class ResponseQueue { } async processQueue() { + if (this.isRequestInProgress) return; if (this.queue.length === 0) return; + this.isRequestInProgress = true; + const responseUpdate = this.queue[0]; let attempts = 0; @@ -57,6 +61,7 @@ export class ResponseQueue { this.queue.shift(); // remove the failed response from the queue } + this.isRequestInProgress = false; this.processQueue(); // process the next item in the queue if any }