Skip to content
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

fix[gen2-sdks]: able to edit and preview when we have no content #3726

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions packages/sdks-tests/src/e2e-tests/editing-empty-content.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { expect } from '@playwright/test';
import { test } from '../helpers/index.js';
import { launchEmbedderAndWaitForSdk, sendContentUpdateMessage } from '../helpers/visual-editor.js';
import { CONTENT } from '../specs/text-block.js';

test.describe('Editing empty content', () => {
test('should be able to edit when content prop is not provided', async ({
page,
sdk,
basePort,
packageName,
}) => {
test.skip(packageName !== 'nuxt');

await launchEmbedderAndWaitForSdk({
// special page added only in nuxt e2e that doesn't pass `content`
path: '/preview-and-edit-content-empty',
page,
sdk,
basePort,
});

await sendContentUpdateMessage({
page,
newContent: CONTENT,
model: 'page',
});

await expect(page.frameLocator('iframe').getByText('Start of text box.')).toBeVisible();

Check failure on line 29 in packages/sdks-tests/src/e2e-tests/editing-empty-content.spec.ts

View workflow job for this annotation

GitHub Actions / Gen 2 SDKs (nuxt)

[nuxt] › editing-empty-content.spec.ts:7:3 › Editing empty content › should be able to edit when content prop is not provided

1) [nuxt] › editing-empty-content.spec.ts:7:3 › Editing empty content › should be able to edit when content prop is not provided Error: expect(locator).toBeVisible() Locator: locator('iframe').contentFrame().getByText('Start of text box.') Expected: visible Received: hidden Call log: - expect.toBeVisible with timeout 5000ms - waiting for locator('iframe').contentFrame().getByText('Start of text box.') 27 | }); 28 | > 29 | await expect(page.frameLocator('iframe').getByText('Start of text box.')).toBeVisible(); | ^ 30 | }); 31 | }); 32 | at /home/runner/work/builder/builder/packages/sdks-tests/src/e2e-tests/editing-empty-content.spec.ts:29:79
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<Content model="page" api-key="abcd" />
</template>

<script setup>
import { Content } from '@builder.io/sdk-vue';
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,13 @@ export default function EnableEditor(props: BuilderEditorProps) {
}, [props.locale]);

return (
<Show when={props.builderContextSignal.value.content}>
<Show
when={
props.builderContextSignal.value.content ||
isPreviewing() ||
isEditing()
}
>
<state.ContentWrapper
{...useTarget({
qwik: {
Expand All @@ -457,6 +463,13 @@ export default function EnableEditor(props: BuilderEditorProps) {
className={getWrapperClassName(
props.content?.testVariationId || props.content?.id
)}
style={{
display:
!props.builderContextSignal.value.content &&
(isPreviewing() || isEditing())
Copy link
Collaborator

@teleaziz teleaziz Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be?

style={(isEditing() || isPreviewing() || props.builderContextSignal.value.content) 
 ? {} 
 : { display: 'none' }}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because we have custom event listeners on the div ref that enable visual editing, we want to visually hide this wrapper div in editing/preview if content is empty, but still render it. if we don't hide it it might break customer layouts because it'll be an empty div with no content.

so:

  • content exists: render div and display: undefined
  • content does not exist but isEditing/isPreviewing: render div and display: 'none'
    • once inline editing kicks in, it will populate the content and re-render, so display style will be removed

your suggestion would display this div in the second case even if we never get content, which we want to avoid.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having said all of that, this logic has a lot of booleans so it would be good to summarize the thought behind it in a comment @sidmohanty11

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added, please take a look.

? 'none'
: undefined,
}}
{...useTarget({
reactNative: {
// currently, we can't set the actual ID here.
Expand Down
Loading