-
Couldn't load subscription status.
- Fork 1.1k
[ENG-10194] Angular SDK – reset builder-context when content id changes #4162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[ENG-10194] Angular SDK – reset builder-context when content id changes #4162
Conversation
|
| contentId: nextId, | ||
| }); | ||
| } | ||
| }, [props.content]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Stale State and Inconsistent Handling in Hook
The onUpdate hook's dependency array omits props.data and props.locale, which can lead to stale rootState. Additionally, testVariationId is handled inconsistently between initial setup and updates (non-null assertion vs. empty string fallback), potentially affecting AB-test functionality.
| const nextId = props.content?.id ?? (props.content as any)?._id; | ||
| const currentId = builderContextSignal.value.content?.id ?? (builderContextSignal.value.content as any)?._id; | ||
|
|
||
| if (nextId && nextId !== currentId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Content Update Hook Fails with Missing IDs
The onUpdate hook's content update logic can lead to stale context. The nextId && nextId !== currentId condition prevents updates when props.content is cleared or lacks an ID. Additionally, currentId's _id fallback may not be preserved after initialization, causing unreliable comparisons and missed content changes.
|
| Command | Status | Duration | Result |
|---|---|---|---|
nx test @snippet/angular-17 |
❌ Failed | 5m 44s | View ↗ |
nx test @snippet/angular-17-ssr |
❌ Failed | 5m 26s | View ↗ |
nx test @snippet/vue |
❌ Failed | 3m | View ↗ |
nx test @snippet/svelte |
❌ Failed | 2m 47s | View ↗ |
nx test @e2e/angular-17 |
❌ Failed | 2m 33s | View ↗ |
nx test @snippet/react |
❌ Failed | 2m 18s | View ↗ |
nx test @e2e/qwik-city |
❌ Failed | 2m 9s | View ↗ |
nx test @snippet/qwik-city |
❌ Failed | 1m 30s | View ↗ |
Additional runs (37) |
❌ Failed | ... | View ↗ |
☁️ Nx Cloud last updated this comment at 2025-10-06 13:30:54 UTC
Description
• Detect
@Input() contentswitch (id differs from current)• Re-initialise
builderContextSignal.content&rootState• Regenerate AB-test visibility script
This ensures repeaters/blocks re-render correctly after SSR refresh and route reuse, eliminating the need for custom
RouteReuseStrategyhacks.JIRA
https://builder-io.atlassian.net/browse/ENG-10194
Loom
https://www.loom.com/share/47d4f285da2a45f2bd1ff6cc82bdad4c?sid=16e0dad3-3104-4fbf-99fd-7f4b1378695a
Note
Detects
contentid changes and re-initializes builder context, root state, and AB-test visibility script.packages/sdks/src/components/content/content.lite.tsx):onUpdatewatcher forprops.contentto detect id changes.builderContextSignal.contentviagetContentInitialValueandbuilderContextSignal.value.rootStateviagetRootStateInitialValue.state.scriptStr) usinggetUpdateVariantVisibilityScriptwith the new ids.onUpdateto support the new watcher.Written by Cursor Bugbot for commit bc31a8c. This will update automatically on new commits. Configure here.