@conform-ed/qti-react 0.0.14 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +6 -3
- package/package.json +1 -1
- package/src/pci/mount.ts +11 -3
package/dist/index.js
CHANGED
|
@@ -3354,10 +3354,13 @@ async function resolveModule(node, registry) {
|
|
|
3354
3354
|
async function mountPci(options) {
|
|
3355
3355
|
const { container, node, registry } = options;
|
|
3356
3356
|
const module = await resolveModule(node, registry);
|
|
3357
|
+
const mountRoot = container.ownerDocument.createElement("div");
|
|
3358
|
+
mountRoot.setAttribute("data-qti-pci-mount", "");
|
|
3359
|
+
container.appendChild(mountRoot);
|
|
3357
3360
|
const markupHost = container.ownerDocument.createElement("div");
|
|
3358
3361
|
markupHost.className = "qti-interaction-markup";
|
|
3359
3362
|
markupHost.innerHTML = serializePciMarkup(node.interactionMarkup?.content);
|
|
3360
|
-
|
|
3363
|
+
mountRoot.appendChild(markupHost);
|
|
3361
3364
|
let resolveReady;
|
|
3362
3365
|
const ready = new Promise((resolve) => {
|
|
3363
3366
|
resolveReady = resolve;
|
|
@@ -3370,7 +3373,7 @@ async function mountPci(options) {
|
|
|
3370
3373
|
onready: (instance2) => resolveReady(instance2),
|
|
3371
3374
|
ondone: (_instance, response, state) => options.ondone?.(pciResponseToValue(response), state)
|
|
3372
3375
|
};
|
|
3373
|
-
const returned = module.getInstance(
|
|
3376
|
+
const returned = module.getInstance(mountRoot, configuration, options.state);
|
|
3374
3377
|
if (returned) {
|
|
3375
3378
|
resolveReady(returned);
|
|
3376
3379
|
}
|
|
@@ -3381,7 +3384,7 @@ async function mountPci(options) {
|
|
|
3381
3384
|
getState: () => instance.getState?.(),
|
|
3382
3385
|
unmount: () => {
|
|
3383
3386
|
instance.oncompleted?.();
|
|
3384
|
-
|
|
3387
|
+
mountRoot.remove();
|
|
3385
3388
|
}
|
|
3386
3389
|
};
|
|
3387
3390
|
}
|
package/package.json
CHANGED
package/src/pci/mount.ts
CHANGED
|
@@ -91,10 +91,18 @@ export async function mountPci(options: PciMountOptions): Promise<PciMountHandle
|
|
|
91
91
|
const { container, node, registry } = options;
|
|
92
92
|
const module = await resolveModule(node, registry);
|
|
93
93
|
|
|
94
|
+
// Each mount owns a root element inside the container, and teardown removes only
|
|
95
|
+
// that root: mounts on a shared container must stay independent because React
|
|
96
|
+
// StrictMode double-invokes the host effect — the cancelled first mount's teardown
|
|
97
|
+
// ran concurrently with the second mount and must not destroy its DOM.
|
|
98
|
+
const mountRoot = container.ownerDocument!.createElement("div");
|
|
99
|
+
mountRoot.setAttribute("data-qti-pci-mount", "");
|
|
100
|
+
container.appendChild(mountRoot);
|
|
101
|
+
|
|
94
102
|
const markupHost = container.ownerDocument!.createElement("div");
|
|
95
103
|
markupHost.className = "qti-interaction-markup";
|
|
96
104
|
markupHost.innerHTML = serializePciMarkup(node.interactionMarkup?.content);
|
|
97
|
-
|
|
105
|
+
mountRoot.appendChild(markupHost);
|
|
98
106
|
|
|
99
107
|
let resolveReady!: (instance: PciInstance) => void;
|
|
100
108
|
const ready = new Promise<PciInstance>((resolve) => {
|
|
@@ -114,7 +122,7 @@ export async function mountPci(options: PciMountOptions): Promise<PciMountHandle
|
|
|
114
122
|
|
|
115
123
|
// The spec delivers the instance via onready; implementations commonly also return
|
|
116
124
|
// it from getInstance. Accept either, first one wins.
|
|
117
|
-
const returned = module.getInstance(
|
|
125
|
+
const returned = module.getInstance(mountRoot, configuration, options.state);
|
|
118
126
|
|
|
119
127
|
if (returned) {
|
|
120
128
|
resolveReady(returned);
|
|
@@ -128,7 +136,7 @@ export async function mountPci(options: PciMountOptions): Promise<PciMountHandle
|
|
|
128
136
|
getState: () => instance.getState?.(),
|
|
129
137
|
unmount: () => {
|
|
130
138
|
instance.oncompleted?.();
|
|
131
|
-
|
|
139
|
+
mountRoot.remove();
|
|
132
140
|
},
|
|
133
141
|
};
|
|
134
142
|
}
|