Skip to content

Commit 44da970

Browse files
yash-builderYash Wadhiasamijaber
authored
fix[qwik-sdk]: ENG-6695 visual editor hangs if editable area (<Content />) is not in the iframe viewport (BuilderIO#3865)
## Description The `CustomEvent` `"initeditingbldr"` was not triggering as expected by ensuring proper event dispatch timing and listener registration. The `useOnDocument("readystatechange")` handler was updated to dispatch the event only after the DOM is fully loaded (`document.readyState === "complete"`) **JIRA**: https://builder-io.atlassian.net/browse/ENG-6695 **Loom** https://www.loom.com/share/0ab5296adbe24bb2b22319f0588f0bbf?sid=4e4b4066-4b18-459e-bc62-7dae1e45c1f9 --------- Co-authored-by: Yash Wadhia <[email protected]> Co-authored-by: Sami Jaber <[email protected]>
1 parent cb3cc9e commit 44da970

File tree

5 files changed

+53
-4
lines changed

5 files changed

+53
-4
lines changed

.changeset/nice-planets-roll.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@builder.io/sdk-qwik": patch
3+
---
4+
5+
Fix: Content editor hangs if not in the iframe viewport.

packages/sdks-tests/src/e2e-tests/editing.spec.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ import { ADD_A_TEXT_BLOCK } from '../specs/duplicated-content-using-nested-symbo
1818
import { EDITING_STYLES } from '../specs/editing-styles.js';
1919
import { ACCORDION_WITH_NO_DETAIL } from '../specs/accordion.js';
2020

21-
const editorTests = ({ noTrustedHosts }: { noTrustedHosts: boolean }) => {
21+
const editorTests = ({
22+
noTrustedHosts,
23+
editorIsInViewPort,
24+
}: {
25+
noTrustedHosts: boolean;
26+
editorIsInViewPort?: boolean;
27+
}) => {
2228
test('correctly updates Text block', async ({ page, basePort, packageName, sdk }) => {
2329
test.skip(
2430
packageName === 'nextjs-sdk-next-app' ||
@@ -27,8 +33,16 @@ const editorTests = ({ noTrustedHosts }: { noTrustedHosts: boolean }) => {
2733
packageName === 'gen1-remix'
2834
);
2935

36+
if (!editorIsInViewPort) {
37+
test.skip(sdk !== 'qwik', 'This is Qwik only test');
38+
}
39+
3040
await launchEmbedderAndWaitForSdk({
31-
path: noTrustedHosts ? '/no-trusted-hosts' : '/editing',
41+
path: noTrustedHosts
42+
? '/no-trusted-hosts'
43+
: editorIsInViewPort
44+
? '/editing'
45+
: '/editing-with-top-padding',
3246
basePort,
3347
page,
3448
sdk,
@@ -82,7 +96,7 @@ const editorTests = ({ noTrustedHosts }: { noTrustedHosts: boolean }) => {
8296
};
8397

8498
test.describe('Visual Editing', () => {
85-
editorTests({ noTrustedHosts: false });
99+
editorTests({ noTrustedHosts: false, editorIsInViewPort: false });
86100
test('correctly updates Box -> Columns when used Inner Layout > Columns option', async ({
87101
page,
88102
packageName,

packages/sdks-tests/src/specs/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ type Page = {
112112
export const PAGES: Record<string, Page> = {
113113
'/': { content: HOMEPAGE },
114114
'/editing': { content: HOMEPAGE, isGen1VisualEditingTest: true },
115+
'/editing-with-top-padding': { content: HOMEPAGE, isGen1VisualEditingTest: true },
115116
'/api-version-v3': { content: CONTENT_WITHOUT_SYMBOLS },
116117
'/api-version-default': { content: CONTENT_WITHOUT_SYMBOLS },
117118
'/can-track-false': { content: HOMEPAGE },
@@ -410,6 +411,11 @@ export const getProps = async (args: {
410411
locale: 'hi-IN',
411412
};
412413
break;
414+
case '/editing-with-top-padding':
415+
extraProps = {
416+
addTopPadding: true,
417+
};
418+
break;
413419
default:
414420
break;
415421
}

packages/sdks/e2e/qwik-city/src/routes/[...index]/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ export default component$(() => {
6161
const contentProps = useBuilderContentLoader();
6262
return (
6363
<>
64+
{contentProps.value.addTopPadding && (
65+
<div style={{ marginTop: '2000px' }} class="builder-margin-element" />
66+
)}
6467
{contentProps.value ? (
6568
<Content
6669
{...(contentProps.value as any)}

packages/sdks/mitosis.config.cjs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1132,14 +1132,35 @@ module.exports = {
11321132
json.hooks.onEvent.push({
11331133
code: hook.code.replaceAll('elementRef', 'element'),
11341134
eventArgName: 'event',
1135-
eventName: 'qvisible',
1135+
eventName: 'readystatechange',
11361136
isRoot: true,
11371137
refName: 'element',
11381138
elementArgName: 'element',
11391139
});
11401140
});
11411141
}
11421142
},
1143+
post: (json) => {
1144+
if (json.name !== 'EnableEditor') return;
1145+
json.imports.push({
1146+
imports: { useOnDocument: 'useOnDocument' },
1147+
path: '@builder.io/qwik',
1148+
});
1149+
return json;
1150+
},
1151+
},
1152+
code: {
1153+
post: (code, json) => {
1154+
if (json.name === 'EnableEditor') {
1155+
code = code.replaceAll(
1156+
`useOn(
1157+
"readystatechange"`,
1158+
`useOnDocument(
1159+
"readystatechange"`
1160+
);
1161+
}
1162+
return code;
1163+
},
11431164
},
11441165
}),
11451166
],

0 commit comments

Comments
 (0)