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[angular-gen2]: new blocks getting added at the top while editing #3932

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

sidmohanty11
Copy link
Contributor

@sidmohanty11 sidmohanty11 commented Feb 26, 2025

Description

https://builder-io.atlassian.net/browse/ENG-7718

Screenshot
If relevant, add a screenshot or two of the changes you made.

Copy link

changeset-bot bot commented Feb 26, 2025

🦋 Changeset detected

Latest commit: ce2e84d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@builder.io/sdk-angular Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

nx-cloud bot commented Feb 26, 2025

View your CI Pipeline Execution ↗ for commit ce2e84d.

Command Status Duration Result
nx test @e2e/nextjs-sdk-next-app ✅ Succeeded 8m 2s View ↗
nx test @e2e/nuxt ✅ Succeeded 8m 20s View ↗
nx test @e2e/react-sdk-next-14-app ✅ Succeeded 8m 1s View ↗
nx test @e2e/qwik-city ✅ Succeeded 8m 3s View ↗
nx test @e2e/angular-16 ✅ Succeeded 7m 1s View ↗
nx test @e2e/angular-19-ssr ✅ Succeeded 6m 47s View ↗
nx test @e2e/gen1-next15-app ✅ Succeeded 6m 15s View ↗
nx test @e2e/react-sdk-next-15-app ✅ Succeeded 6m 31s View ↗
Additional runs (36) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2025-02-28 10:10:32 UTC

Copy link

gitguardian bot commented Feb 26, 2025

️✅ There are no secrets present in this pull request anymore.

If these secrets were true positive and are still valid, we highly recommend you to revoke them.
While these secrets were previously flagged, we no longer have a reference to the
specific commits where they were detected. Once a secret has been leaked into a git
repository, you should consider it compromised, even if it was deleted immediately.
Find here more information about risks.


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Comment on lines +469 to +472
test.skip(
packageName === 'vue',
`Failing on the CI: TypeError: Cannot read properties of null (reading 'namespaceURI')`
);
Copy link
Contributor Author

@sidmohanty11 sidmohanty11 Feb 28, 2025

Choose a reason for hiding this comment

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

this works on local

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Screenshot 2025-02-28 at 3 17 15 PM

@shubham-builder
Copy link
Contributor

@sidmohanty11 Let me know if I get this right... ngAfterContentInit moves the newly added block to top, so ngAfterContentChecked causes rerender based on the "shouldUpdate" flag that moves the block to correct position ?

@sidmohanty11
Copy link
Contributor Author

@shubham-builder ngAfterContentInit gets called only once at the start of the render which places/adds blocks in the array that are already present in the content JSON and this is the reason why if we start from scratch, we're unable to repro this issue.

This never gets called again and the myContent array doesn't update the nodes when blocks changes. We need to use the ngAfterContentChecked hook because this runs every time change detection is triggered and runs after the children have been initialized. This helps us to project them after they are completely ready.

code = code.replace(
'ngOnChanges(changes: SimpleChanges) {',
// trigger a re-render of the view when blocks got updated and the new children content has been fully initialized
`ngAfterContentChecked() {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use our compileContext to add this instead of using a regex?

@@ -455,4 +456,96 @@ test.describe('Visual Editing', () => {
await page.frameLocator('iframe').getByText('Bye').waitFor();
});
});

test.describe('New Block addition and deletion', () => {
test('should add new block below the last block', async ({
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we also check that adding a block in the middle from [a,b,c] to [a,b,d,c] works as expected? In case there's issues with stuff always getting pushed to the end too

test.skip(packageName === 'nextjs-sdk-next-app');
test.skip(
packageName === 'vue',
`Failing on the CI: TypeError: Cannot read properties of null (reading 'namespaceURI')`
Copy link
Contributor

Choose a reason for hiding this comment

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

I've seen this intermittently happen in multiple tests...no clue what it's about yet

code = code.replace(/^\s*\/\/\s*@ts-expect-error.*$/gm, '');
code = code.replace(
'ngOnChanges(changes: SimpleChanges) {',
// trigger a re-render of the view when blocks got updated and the new children content has been fully initialized
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we document here in more detail? A brief summary of why it's needed, essentially a tl;dr of your looms. You'll know how to phrase this in the most accurate way, but something along the lines of:

Since the angular SDK manually handles the creation of the dynamic blocks and attaching them as children of BlocksWrapper in the DOM, it must also manually handle their re-renders on content change in the visual editor. ngAfterContentChecked runs after children were checked for changes, which is the earlier point we can safely append new blocks, otherwise they are appended outside the existing array of Blocks, therefore pushed to the top of the list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants