Fix float teaser delay from API embed settings being ignored#70
Merged
Conversation
The welcome sequence was armed at mount with whatever teaser delay was known at that moment — for script-tag embeds that's the 3s default, since the async /embed/config fetch hasn't resolved yet. When the API config later arrived via update(), maybeStartWelcomeSequence() bailed out because the sequence was already marked as started, so a dashboard teaser delay (e.g. 30000ms) never took effect and the teaser always appeared after ~3s. syncTeaserState() now reschedules the pending timers when the resolved delay changes, crediting the time already waited so the teaser fires at the configured delay relative to mount. Once the teaser has been delivered or the sequence cancelled (e.g. the float was opened), a late config refresh no longer re-arms it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U6W4LcRde56iDNCwCMj76Q
Contributor
📦 Snapshot ReleasePublished snapshot packages for this PR: pnpm add @perspective-ai/sdk@1.14.1-pr-70-20260709215800
pnpm add @perspective-ai/sdk-react@1.14.1-pr-70-20260709215800Or use the npm tag (always points to the latest snapshot from this PR): pnpm add @perspective-ai/sdk@pr-70
pnpm add @perspective-ai/sdk-react@pr-70 |
There was a problem hiding this comment.
Pull request overview
Fixes float teaser delay being ignored when dashboard/API embed settings arrive asynchronously after the float bubble mounts, by rescheduling the welcome sequence timers to respect the resolved embedSettings.teaser.delay (crediting time already elapsed since mount).
Changes:
- Track which teaser delay the welcome sequence was armed with and when, so pending timers can be rescheduled when API config changes the delay.
- Reschedule teaser + chime timers on delay changes while the teaser is still pending, without re-arming after the teaser has already fired.
- Add regression tests covering async delay reschedule, unchanged-delay refresh behavior, and no re-arm after the teaser has shown; add a patch changeset for
@perspective-ai/sdk.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/sdk/src/float.ts | Adds arm-tracking and rescheduling logic so async API teaser delay updates take effect. |
| packages/sdk/src/float.test.ts | Adds regression tests for delay rescheduling and non-rearming scenarios. |
| .changeset/teaser-delay-reschedule.md | Patch changeset documenting the behavioral fix for @perspective-ai/sdk. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Instead of arming the welcome sequence at mount with the default delay
and rescheduling when the API config arrives, script-tag embeds now
defer arming entirely while the config fetch is in flight (internal
_apiConfigPending flag, cleared by update({_apiConfig})). This removes
any chance of the teaser firing early on a slow fetch; fetchEmbedConfig
never rejects (it resolves with the default theme on error/timeout), so
the deferral always ends.
The delay is measured from a persistent anchor set when the sequence
first could have started (mount, or re-enable after a disable), so the
eventual arm credits the time already waited, and repeated delay
changes on a still-pending teaser reschedule against the same anchor
rather than the latest reschedule. Addresses both Copilot review
comments on the previous approach.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01U6W4LcRde56iDNCwCMj76Q
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Dashboard embed settings for the float teaser delay (
embedSettings.teaser.delay) had no effect on customer sites. Reported for researchmype6y13(embedded on greencountryhomebuyers.com): the delay was set to 30000ms and the config API returned it correctly, but the teaser always appeared after ~3 seconds.Root cause
For script-tag embeds (
data-perspective-float), the float bubble mounts immediately while the embed config is fetched asynchronously.createFloatBubblearmed the welcome sequence (teaser + chime timers) at mount using the delay known at that moment — the hardcoded 3000ms default — and setwelcomeSequenceStarted. When the API config arrived moments later viaupdate()→syncTeaserState(),maybeStartWelcomeSequence()returned early because the sequence was already marked as started, so the configured delay was silently ignored.Fix
_apiConfigPendingflag; the welcome sequence does not arm untilupdate({ _apiConfig })clears it, so the teaser can never fire on the default delay while waiting for the API.fetchEmbedConfignever rejects (it resolves with the default theme on error/timeout), so the deferral always ends.Testing
@perspective-ai/sdk.🤖 Generated with Claude Code
https://claude.ai/code/session_01U6W4LcRde56iDNCwCMj76Q