Skip to content

Commit 1cb45d7

Browse files
committed
fix(web): preserve other pointer holds during release cleanup
1 parent d5be5cf commit 1cb45d7

3 files changed

Lines changed: 48 additions & 29 deletions

File tree

‎apps/web/src/components/chat/HtmlRenderFrame.browser.test.tsx‎

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ describe("HtmlRenderFrame", () => {
4242
});
4343
});
4444

45-
it.each([false, true])("holds sizing until release (outside frame: %s)", async (outside) => {
45+
it.each(["inside", "outside", "touch"])("holds sizing until release: %s", async (kind) => {
46+
const outside = kind === "outside";
4647
const url = URL.createObjectURL(
4748
new Blob(
4849
[
@@ -84,30 +85,44 @@ it.each([false, true])("holds sizing until release (outside frame: %s)", async (
8485
const box = frame.getBoundingClientRect();
8586
const x = outer.left + box.left + 30,
8687
y = outer.top + box.top + 30;
87-
await cdp().send("Input.dispatchMouseEvent", {
88-
type: "mousePressed",
89-
x,
90-
y,
91-
button: "left",
92-
buttons: 1,
93-
clickCount: 1,
94-
});
95-
await vi.waitFor(() => expect(pin).toHaveBeenLastCalledWith(true));
96-
expect(frame.clientHeight).toBe(216);
97-
await cdp().send("Input.dispatchMouseEvent", {
98-
type: "mouseMoved",
99-
x,
100-
y: outside ? outer.top + box.bottom + 30 : y,
101-
buttons: 1,
102-
});
103-
await cdp().send("Input.dispatchMouseEvent", {
104-
type: "mouseReleased",
105-
x,
106-
y: outside ? outer.top + box.bottom + 30 : y,
107-
button: "left",
108-
buttons: 0,
109-
clickCount: 1,
110-
});
88+
if (kind === "touch") {
89+
const first = { x, y, id: 11 };
90+
await cdp().send("Input.dispatchTouchEvent", { type: "touchStart", touchPoints: [first] });
91+
await vi.waitFor(() => expect(pin).toHaveBeenLastCalledWith(true));
92+
await cdp().send("Input.dispatchTouchEvent", {
93+
type: "touchStart",
94+
touchPoints: [first, { x, y: outer.top + box.bottom + 30, id: 12 }],
95+
});
96+
await cdp().send("Input.dispatchTouchEvent", { type: "touchEnd", touchPoints: [first] });
97+
expect(pin).toHaveBeenLastCalledWith(true);
98+
expect(frame.clientHeight).toBe(216);
99+
await cdp().send("Input.dispatchTouchEvent", { type: "touchEnd", touchPoints: [] });
100+
} else {
101+
await cdp().send("Input.dispatchMouseEvent", {
102+
type: "mousePressed",
103+
x,
104+
y,
105+
button: "left",
106+
buttons: 1,
107+
clickCount: 1,
108+
});
109+
await vi.waitFor(() => expect(pin).toHaveBeenLastCalledWith(true));
110+
expect(frame.clientHeight).toBe(216);
111+
await cdp().send("Input.dispatchMouseEvent", {
112+
type: "mouseMoved",
113+
x,
114+
y: outside ? outer.top + box.bottom + 30 : y,
115+
buttons: 1,
116+
});
117+
await cdp().send("Input.dispatchMouseEvent", {
118+
type: "mouseReleased",
119+
x,
120+
y: outside ? outer.top + box.bottom + 30 : y,
121+
button: "left",
122+
buttons: 0,
123+
clickCount: 1,
124+
});
125+
}
111126
await vi.waitFor(() => expect(pin).toHaveBeenLastCalledWith(false));
112127
await vi.waitFor(() => expect(frame.clientHeight).toBe(316));
113128
if (!outside) expect(cancelled).toBe(false);

‎apps/web/src/components/files/BrowserDocumentFrame.tsx‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,16 @@ export function HtmlRenderDocument(props: {
246246
useEffect(() => {
247247
if (!pointerHeld) return;
248248
const release = (event: Event) => {
249-
if (event instanceof PointerEvent && event.buttons !== 0) return;
249+
if (event.type === "pointermove" && event instanceof PointerEvent && event.buttons !== 0)
250+
return;
250251
frameRef.current?.contentWindow?.postMessage(
251-
{ jsonrpc: "2.0", method: HTML_RENDER_POINTER_RELEASE_METHOD },
252+
{
253+
jsonrpc: "2.0",
254+
method: HTML_RENDER_POINTER_RELEASE_METHOD,
255+
...(event instanceof PointerEvent ? { params: { pointerId: event.pointerId } } : {}),
256+
},
252257
"*",
253258
);
254-
setPointerHeld(false);
255259
};
256260
window.addEventListener("pointerup", release, true);
257261
window.addEventListener("pointercancel", release, true);

‎packages/shared/src/htmlRender.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ function rootRule(theme: HtmlRenderTheme): string {
382382
// Apply overridable theme CSS before paint and strip the fragment before routing; framed navigation uses the client.
383383
// Forward shortcuts after page handlers; text fields retain their keys.
384384
// Hold height reports during gestures because iframe resizing can cancel a page's drag.
385-
const BOOTSTRAP_SCRIPT = `(function(){var s=document.getElementById("t3-theme"),n=0;if(!s)return;var b=${JSON.stringify(BASE_CSS)};function a(t){if(!t||typeof t!=="object"||!t.variables||typeof t.variables!=="object")return;var c=":root{color-scheme:"+(t.appearance==="light"?"light":"dark")+";";for(var k in t.variables){if(/^--[a-z0-9-]+$/.test(k))c+=k+":"+String(t.variables[k]).replace(/[;{}<>]/g,"")+";";}s.textContent=c+"}"+b;}try{var m=/[#&]${THEME_FRAGMENT_KEY}=([^&]*)/.exec(location.hash);if(m){a(JSON.parse(decodeURIComponent(m[1])));history.replaceState(history.state,"",location.pathname+location.search);}}catch(e){}window.addEventListener("message",function(e){var d=e.data,p=d&&d.params;if(d&&d.jsonrpc==="2.0"&&d.method===${JSON.stringify(HOST_CONTEXT_CHANGED_METHOD)}&&p&&p.styles)a({appearance:p.theme,variables:p.styles.variables});});document.addEventListener("click",function(e){var l=e.isTrusted?e.composedPath().find(function(t){return t&&t.matches&&t.matches("a[href]");}):null,u;if(!l)return;try{u=new URL(l.getAttribute("href"),document.baseURI);}catch(x){return;}if(!/^https?:$/.test(u.protocol)||u.href.split("#")[0]===location.href.split("#")[0])return;if(window.parent!==window){e.preventDefault();window.parent.postMessage({jsonrpc:"2.0",id:"t3-link-"+(++n),method:${JSON.stringify(OPEN_LINK_METHOD)},params:{url:u.href,metaKey:e.metaKey,ctrlKey:e.ctrlKey}},"*");}else{l.setAttribute("target","_blank");l.setAttribute("rel","noopener");}},true);if(window.parent!==window){var h,o,P={},D=0,Y=function(p){window.parent.postMessage({jsonrpc:"2.0",method:${JSON.stringify(POINTER_HELD_METHOD)},params:{held:p}},"*");},z=function(){if(D)return;var r=document.documentElement,v=Math.ceil(r.scrollHeight>r.clientHeight?r.scrollHeight:r.getBoundingClientRect().height);if(v===h)return;h=v;window.parent.postMessage({jsonrpc:"2.0",method:${JSON.stringify(SIZE_CHANGED_METHOD)},params:{height:v}},"*");};if(window.ResizeObserver){o=new ResizeObserver(z);o.observe(document.documentElement);}document.addEventListener("DOMContentLoaded",function(){if(o&&document.body)o.observe(document.body);z();});window.addEventListener("load",z);var R=function(){if(!D)return;P={};D=0;Y(false);requestAnimationFrame(z);};window.addEventListener("message",function(e){var d=e.data;if(e.source===window.parent&&d&&d.jsonrpc==="2.0"&&d.method===${JSON.stringify(HTML_RENDER_POINTER_RELEASE_METHOD)})R();});window.addEventListener("pointermove",function(e){if(e.isTrusted&&e.buttons===0)R();},true);var U=function(e){if(!P[e.pointerId])return;delete P[e.pointerId];if(--D)return;Y(false);requestAnimationFrame(z);};window.addEventListener("pointerdown",function(e){if(!e.isTrusted||P[e.pointerId])return;P[e.pointerId]=1;if(!D++)Y(true);},true);window.addEventListener("pointerup",U,true);window.addEventListener("pointercancel",U,true);window.addEventListener("blur",R);window.addEventListener("click",function(e){var t=e.composedPath()[0],u;if(!e.isTrusted||e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||!t||t.tagName!=="IMG"||t.closest("a[href],button"))return;u=t.currentSrc||t.src;if(u)setTimeout(function(){if(!e.defaultPrevented)window.parent.postMessage({jsonrpc:"2.0",method:${JSON.stringify(OPEN_IMAGE_METHOD)},params:{src:u,name:t.alt||t.title||""}},"*");});});var K=[],B=[],C=${JSON.stringify(EVENT_CODE_SHORTCUT_KEYS)};window.addEventListener("message",function(e){var d=e.data,p=d&&d.params;if(e.source===window.parent&&d&&d.jsonrpc==="2.0"&&d.method===${JSON.stringify(SHORTCUTS_METHOD)}&&p&&Array.isArray(p.shortcuts)&&Array.isArray(p.blocked)){K=p.shortcuts;B=p.blocked;}});window.addEventListener("keydown",function(e){var t=e.composedPath()[0],c=e.code||"",l=e.key.toLowerCase(),x=/^[a-z]$/.test(l)?[l]:[l,/^Key[A-Z]$/.test(c)?c.slice(3).toLowerCase():"",C.hasOwnProperty(c)?C[c]:""],f,m=function(s){return s&&s.metaKey===e.metaKey&&s.ctrlKey===e.ctrlKey&&s.shiftKey===e.shiftKey&&s.altKey===e.altKey&&x.indexOf(s.key)>-1;};if(!e.isTrusted||e.isComposing||e.getModifierState("AltGraph")&&!/^[a-z0-9]$/i.test(e.key)||t&&(t.isContentEditable||/^(?:INPUT|TEXTAREA|SELECT)$/.test(t.tagName))||!K.some(m)||B.some(m))return;f=function(v){window.removeEventListener("keydown",f);if(v!==e||e.defaultPrevented)return;e.preventDefault();window.parent.postMessage({jsonrpc:"2.0",method:${JSON.stringify(KEY_DOWN_METHOD)},params:{key:e.key,code:e.code,metaKey:e.metaKey,ctrlKey:e.ctrlKey,shiftKey:e.shiftKey,altKey:e.altKey,repeat:e.repeat}},"*");};window.addEventListener("keydown",f);setTimeout(function(){window.removeEventListener("keydown",f);});},true);}})();`;
385+
const BOOTSTRAP_SCRIPT = `(function(){var s=document.getElementById("t3-theme"),n=0;if(!s)return;var b=${JSON.stringify(BASE_CSS)};function a(t){if(!t||typeof t!=="object"||!t.variables||typeof t.variables!=="object")return;var c=":root{color-scheme:"+(t.appearance==="light"?"light":"dark")+";";for(var k in t.variables){if(/^--[a-z0-9-]+$/.test(k))c+=k+":"+String(t.variables[k]).replace(/[;{}<>]/g,"")+";";}s.textContent=c+"}"+b;}try{var m=/[#&]${THEME_FRAGMENT_KEY}=([^&]*)/.exec(location.hash);if(m){a(JSON.parse(decodeURIComponent(m[1])));history.replaceState(history.state,"",location.pathname+location.search);}}catch(e){}window.addEventListener("message",function(e){var d=e.data,p=d&&d.params;if(d&&d.jsonrpc==="2.0"&&d.method===${JSON.stringify(HOST_CONTEXT_CHANGED_METHOD)}&&p&&p.styles)a({appearance:p.theme,variables:p.styles.variables});});document.addEventListener("click",function(e){var l=e.isTrusted?e.composedPath().find(function(t){return t&&t.matches&&t.matches("a[href]");}):null,u;if(!l)return;try{u=new URL(l.getAttribute("href"),document.baseURI);}catch(x){return;}if(!/^https?:$/.test(u.protocol)||u.href.split("#")[0]===location.href.split("#")[0])return;if(window.parent!==window){e.preventDefault();window.parent.postMessage({jsonrpc:"2.0",id:"t3-link-"+(++n),method:${JSON.stringify(OPEN_LINK_METHOD)},params:{url:u.href,metaKey:e.metaKey,ctrlKey:e.ctrlKey}},"*");}else{l.setAttribute("target","_blank");l.setAttribute("rel","noopener");}},true);if(window.parent!==window){var h,o,P={},D=0,Y=function(p){window.parent.postMessage({jsonrpc:"2.0",method:${JSON.stringify(POINTER_HELD_METHOD)},params:{held:p}},"*");},z=function(){if(D)return;var r=document.documentElement,v=Math.ceil(r.scrollHeight>r.clientHeight?r.scrollHeight:r.getBoundingClientRect().height);if(v===h)return;h=v;window.parent.postMessage({jsonrpc:"2.0",method:${JSON.stringify(SIZE_CHANGED_METHOD)},params:{height:v}},"*");};if(window.ResizeObserver){o=new ResizeObserver(z);o.observe(document.documentElement);}document.addEventListener("DOMContentLoaded",function(){if(o&&document.body)o.observe(document.body);z();});window.addEventListener("load",z);var R=function(){if(!D)return;P={};D=0;Y(false);requestAnimationFrame(z);};window.addEventListener("message",function(e){var d=e.data;if(e.source===window.parent&&d&&d.jsonrpc==="2.0"&&d.method===${JSON.stringify(HTML_RENDER_POINTER_RELEASE_METHOD)}){if(d.params&&typeof d.params.pointerId==="number")U(d.params);else R();}});window.addEventListener("pointermove",function(e){if(e.isTrusted&&e.buttons===0)U(e);},true);var U=function(e){if(!P[e.pointerId])return;delete P[e.pointerId];if(--D)return;Y(false);requestAnimationFrame(z);};window.addEventListener("pointerdown",function(e){if(!e.isTrusted||P[e.pointerId])return;P[e.pointerId]=1;if(!D++)Y(true);},true);window.addEventListener("pointerup",U,true);window.addEventListener("pointercancel",U,true);window.addEventListener("blur",R);window.addEventListener("click",function(e){var t=e.composedPath()[0],u;if(!e.isTrusted||e.defaultPrevented||e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||!t||t.tagName!=="IMG"||t.closest("a[href],button"))return;u=t.currentSrc||t.src;if(u)setTimeout(function(){if(!e.defaultPrevented)window.parent.postMessage({jsonrpc:"2.0",method:${JSON.stringify(OPEN_IMAGE_METHOD)},params:{src:u,name:t.alt||t.title||""}},"*");});});var K=[],B=[],C=${JSON.stringify(EVENT_CODE_SHORTCUT_KEYS)};window.addEventListener("message",function(e){var d=e.data,p=d&&d.params;if(e.source===window.parent&&d&&d.jsonrpc==="2.0"&&d.method===${JSON.stringify(SHORTCUTS_METHOD)}&&p&&Array.isArray(p.shortcuts)&&Array.isArray(p.blocked)){K=p.shortcuts;B=p.blocked;}});window.addEventListener("keydown",function(e){var t=e.composedPath()[0],c=e.code||"",l=e.key.toLowerCase(),x=/^[a-z]$/.test(l)?[l]:[l,/^Key[A-Z]$/.test(c)?c.slice(3).toLowerCase():"",C.hasOwnProperty(c)?C[c]:""],f,m=function(s){return s&&s.metaKey===e.metaKey&&s.ctrlKey===e.ctrlKey&&s.shiftKey===e.shiftKey&&s.altKey===e.altKey&&x.indexOf(s.key)>-1;};if(!e.isTrusted||e.isComposing||e.getModifierState("AltGraph")&&!/^[a-z0-9]$/i.test(e.key)||t&&(t.isContentEditable||/^(?:INPUT|TEXTAREA|SELECT)$/.test(t.tagName))||!K.some(m)||B.some(m))return;f=function(v){window.removeEventListener("keydown",f);if(v!==e||e.defaultPrevented)return;e.preventDefault();window.parent.postMessage({jsonrpc:"2.0",method:${JSON.stringify(KEY_DOWN_METHOD)},params:{key:e.key,code:e.code,metaKey:e.metaKey,ctrlKey:e.ctrlKey,shiftKey:e.shiftKey,altKey:e.altKey,repeat:e.repeat}},"*");};window.addEventListener("keydown",f);setTimeout(function(){window.removeEventListener("keydown",f);});},true);}})();`;
386386

387387
function bootstrapMarkup(markup: string): string {
388388
const dark = htmlRenderTheme(T3_CODE_DARK_THEME_COLORS, "dark");

0 commit comments

Comments
 (0)