///
import { NAME, pattern, UI, Writable } from "commontools";
/**
* Reproduction case for late subscriber initial value bug.
*
* Bug: When multiple CellHandle instances subscribe to the same cell with the
* same schema key, late subscribers would miss the initial value. This happened
* because the subscription was already established, so no new backend request
* was made, and the late subscriber's CellHandle never received the cached value.
*
* Example: ct-input binds to a cell with stringSchema, creating a new CellHandle.
* Text interpolation {value} also subscribes to the same cell with the same schema.
* On initial page load, the text interpolation would show blank because it subscribed
* after the initial value was already sent to the first subscriber.
*
* Fix: In connection.subscribe(), when adding a CellHandle to an existing
* subscription, copy the cached value from an existing subscriber to the new one.
*
* To test:
* 1. Deploy this pattern with `piece new`
* 2. On initial page load, all "Interpolated" values should show their initial values
* 3. Interacting with any component should update its interpolated value
*/
interface Output {
[NAME]: string;
textValue: string;
textareaValue: string;
checkboxValue: boolean;
}
export default pattern, Output>(() => {
const textValue = Writable.of("hello");
const textareaValue = Writable.of("multi\nline");
const checkboxValue = Writable.of(true);
return {
[NAME]: "Late Subscriber Repro",
[UI]: (
ct-input
Interpolated: {textValue}
ct-textarea
Interpolated: {textareaValue}
ct-checkboxToggle me
Interpolated: [{checkboxValue}]
If any "Interpolated" value is blank on initial page load, the late
subscriber bug is present. All values should appear immediately.