Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## Unreleased

### slidev-addon-slide-quiz

#### Fixed
- On Slidev 0.50 and 51, leaving a `quiz` or `quiz-results` slide never cleared the active question, so phones kept showing it after the presenter moved on. 0.5.0 read the slide number from the `onSlideEnter`/`onSlideLeave` arguments, which only Slidev 52 passes. The layouts now use the slide's own number from `useSlideContext()`, which every supported version provides.
- A `quiz` slide with missing fields no longer activates its question when the presenter reaches it. It never registered the question, so there was nothing to activate.

## 0.7.0 (slide-quiz) / 0.5.0 (slidev-addon-slide-quiz), 2026-10-07

**Upgrading:** copy the serverless functions again and, on Slidev, copy `public/quiz.html` again, then redeploy. Functions older than this release reject multi-select questions with a 400, and an older audience page lets people pick only one option. See "Upgrading" in the README.
Expand Down
54 changes: 36 additions & 18 deletions packages/slidev-addon-slide-quiz/composables/useQuizManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { inject, shallowRef, readonly, onScopeDispose, computed } from "vue";
import type { Ref, ComputedRef } from "vue";
import { inject, shallowRef, readonly, onScopeDispose, onMounted, computed, toValue } from "vue";
import type { Ref, ComputedRef, MaybeRefOrGetter } from "vue";
import { onSlideEnter, onSlideLeave, useIsSlideActive, useSlideContext } from "@slidev/client";
import { MULTI_HINT, MULTI_RESULTS_NOTE, responsesText } from "slide-quiz";
import type { PresenterQuizManager, QuestionPayload } from "slide-quiz";
import { QUIZ_MANAGER_KEY, QUIZ_CONFIG_KEY } from "../injectionKeys";
Expand Down Expand Up @@ -64,32 +65,49 @@ export function useQuizManager() {
}, 100);
}

/** Activate a question on behalf of the slide numbered `slideNo`. */
function setActive(quizId: string, slideNo: number) {
if (!manager) return;
activeSlideNo = slideNo;
manager.setActiveQuestion(quizId);
}

/** Clear the active question when slide `slideNo` is left, if that slide set it. */
function clearActive(slideNo: number) {
if (!manager || activeSlideNo !== slideNo) return;
activeSlideNo = null;
manager.clearActiveQuestion();
}

return {
manager,
config,
configured: manager !== null,
online: manager ? useNanoStore(manager.store.online) : readonly(shallowRef(0)),
results: manager ? useNanoStore(manager.store.results) : readonly(shallowRef({})),
registerQuestion,
setActive,
clearActive,
};
}

/**
* Make `quizId` the active question while this slide is on screen, and clear
* it when the slide is left. An undefined `quizId` activates nothing.
*
* Slidev mounts slides ahead of time, so on mount only the slide on screen
* activates. The slide number comes from useSlideContext(): Slidev 52 passes
* (to, from) to onSlideEnter/onSlideLeave, but 0.50 and 51 pass nothing.
* Call it after the layout's own onMounted, so a question registered on mount
* is registered before it is activated.
*/
export function useActiveQuestion(quizId: MaybeRefOrGetter<string | undefined>) {
const manager = inject(QUIZ_MANAGER_KEY, null);
const isSlideActive = useIsSlideActive();
const { $page } = useSlideContext();

function activate() {
const id = toValue(quizId);
if (!manager || !id) return;
activeSlideNo = $page.value;
manager.setActiveQuestion(id);
}

onMounted(() => {
if (isSlideActive.value) activate();
});
onSlideEnter(activate);
onSlideLeave(() => {
if (!manager || activeSlideNo !== $page.value) return;
activeSlideNo = null;
manager.clearActiveQuestion();
});
}

// Text shared with the Reveal.js renderers and the audience page
export { MULTI_HINT, MULTI_RESULTS_NOTE, responsesText };

Expand Down
18 changes: 4 additions & 14 deletions packages/slidev-addon-slide-quiz/layouts/quiz-results.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<script setup lang="ts">
import { inject, ref, computed, onMounted } from "vue";
import { onSlideEnter, onSlideLeave, useIsSlideActive, useSlideContext } from "@slidev/client";
import { useSlideContext } from "@slidev/client";
import SlideQuizResults from "../components/SlideQuizResults.vue";
import SlideQuizWordCloud from "../components/SlideQuizWordCloud.vue";
import SlideQuizError from "../components/SlideQuizError.vue";
import SlideQuizSyncError from "../components/SlideQuizSyncError.vue";
import { useQuizManager } from "../composables/useQuizManager";
import { useActiveQuestion, useQuizManager } from "../composables/useQuizManager";
import { QUIZ_CONFIG_ERROR_KEY } from "../injectionKeys";
import type { QuizType } from "slide-quiz";

Expand All @@ -19,10 +19,8 @@ const props = defineProps<{
const type = (props.type ?? "choice") as QuizType;
// YAML reads `text: 27` as a number; the engine and the sync function expect strings.
const options = (props.options ?? []).map((o) => ({ label: String(o.label), text: String(o.text), correct: o.correct }));
const { configured, registerQuestion, setActive, clearActive } = useQuizManager();
const { configured, registerQuestion } = useQuizManager();
const configError = inject(QUIZ_CONFIG_ERROR_KEY, null);
// Slidev mounts slides ahead of time; only the slide on screen may activate its question.
const isSlideActive = useIsSlideActive();
const { $page, $clicks } = useSlideContext();

const validTypes = ["choice", "multi", "text"];
Expand All @@ -48,18 +46,10 @@ if (configured && props.quizId && !typeError) {
}

onMounted(() => {
if (configured && props.quizId && isSlideActive.value) setActive(props.quizId, $page.value);
entered.value = true;
});

onSlideEnter((to) => {
if (configured && props.quizId) setActive(props.quizId, to);
entered.value = true;
});

onSlideLeave((_to, from) => {
if (configured && from !== undefined) clearActive(from);
});
useActiveQuestion(() => props.quizId);
</script>

<template>
Expand Down
18 changes: 5 additions & 13 deletions packages/slidev-addon-slide-quiz/layouts/quiz.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script setup lang="ts">
import { inject, onMounted } from "vue";
import { onSlideEnter, onSlideLeave, useIsSlideActive, useSlideContext } from "@slidev/client";
import { useSlideContext } from "@slidev/client";
import SlideQuizQuestion from "../components/SlideQuizQuestion.vue";
import SlideQuizError from "../components/SlideQuizError.vue";
import SlideQuizSyncError from "../components/SlideQuizSyncError.vue";
import { useQuizManager } from "../composables/useQuizManager";
import { useActiveQuestion, useQuizManager } from "../composables/useQuizManager";
import { QUIZ_CONFIG_ERROR_KEY } from "../injectionKeys";
import type { QuizType } from "slide-quiz";

Expand All @@ -20,10 +20,8 @@ const props = defineProps<{
const type = (props.type ?? "choice") as QuizType;
// YAML reads `text: 27` as a number; the engine and the sync function expect strings.
const options = (props.options ?? []).map((o) => ({ label: String(o.label), text: String(o.text) }));
const { configured, config, registerQuestion, setActive, clearActive } = useQuizManager();
const { configured, config, registerQuestion } = useQuizManager();
const configError = inject(QUIZ_CONFIG_ERROR_KEY, null);
// Slidev mounts slides ahead of time; only the slide on screen may activate its question.
const isSlideActive = useIsSlideActive();
const { $page } = useSlideContext();

// A slide's hintText applies to free-text and multi-select questions; the
Expand All @@ -47,16 +45,10 @@ onMounted(() => {
options,
hint,
}, $page.value);
if (props.quizId && isSlideActive.value) setActive(props.quizId, $page.value);
});

onSlideEnter((to) => {
if (configured && props.quizId) setActive(props.quizId, to);
});

onSlideLeave((_to, from) => {
if (configured && from !== undefined) clearActive(from);
});
// A slide with missing fields registered nothing, so it activates nothing either
useActiveQuestion(() => (missingProps.length ? undefined : props.quizId));
</script>

<template>
Expand Down
2 changes: 1 addition & 1 deletion skills/slide-quiz-debug/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ The audience page is older than the deck. The presenter still counts those votes

**Symptom:** the `online` counter on the deck increments, but phones never see a question.

1. The deck must be on a quiz slide. Navigating to a non-quiz slide broadcasts `activeQuestionId: null`, which the audience page renders as "Waiting for the next question".
1. The deck must be on a quiz slide. Navigating to a non-quiz slide broadcasts `activeQuestionId: null`, which the audience page renders as "Waiting for the next question". The opposite symptom, phones still showing a question after the deck left its slide, is addon 0.5.0 on Slidev 0.50 or 51, which never cleared it. Fixed after addon 0.5.0, upgrade.
2. `quizGroupId` on the audience page must match the deck exactly. For Slidev, the QR code URL passes it as a query parameter; if the user typed the URL by hand it is missing. The shipped `quiz.html` then asks people to scan the QR code (addon 0.5+; older copies silently joined the public demo group). Scan the QR code, or append `?wsUrl=...&quizGroupId=...`.
3. Two presenter tabs open with the same `quizGroupId` will fight: each ignores the other's sync and broadcasts its own state. Close all but one.
4. Sync history: late joiners receive the last five minutes of the sync stream. If the presenter has been idle on a quiz slide for longer than that, the keepalive (every 120 seconds) should still cover it. If it does not, the keepalive timer was cancelled, which happens after `destroy()`; reload the deck.
Expand Down
Loading