Skip to content

fix[angular-gen2]: Better error handling on form submissions #4031

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

Merged

Conversation

anaghav2023
Copy link
Contributor

@anaghav2023 anaghav2023 commented Apr 16, 2025

Copy link

changeset-bot bot commented Apr 16, 2025

🦋 Changeset detected

Latest commit: 92a354e

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

This PR includes changesets to release 10 packages
Name Type
@builder.io/sdk Patch
@builder.io/react Patch
@builder.io/sdk-angular Patch
@builder.io/sdk-react-nextjs Patch
@builder.io/sdk-qwik Patch
@builder.io/sdk-react Patch
@builder.io/sdk-react-native Patch
@builder.io/sdk-solid Patch
@builder.io/sdk-svelte Patch
@builder.io/sdk-vue 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

@anaghav2023 anaghav2023 requested review from a team and yash-builder and removed request for a team April 16, 2025 09:01
Copy link

nx-cloud bot commented Apr 16, 2025

View your CI Pipeline Execution ↗ for commit 7e08c64.

Command Status Duration Result
nx test @e2e/nuxt ✅ Succeeded 9m 54s View ↗
nx test @e2e/nextjs-sdk-next-app ✅ Succeeded 9m 41s View ↗
nx test @e2e/qwik-city ✅ Succeeded 9m 1s View ↗
nx test @e2e/sveltekit ✅ Succeeded 6m 41s View ↗
nx test @e2e/vue ✅ Succeeded 5m 25s View ↗
nx test @e2e/remix ✅ Succeeded 6m 22s View ↗
nx test @e2e/svelte ✅ Succeeded 5m 42s View ↗
nx test @e2e/solid ✅ Succeeded 6m 20s View ↗
Additional runs (36) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2025-04-22 08:43:28 UTC

if (
props.sendSubmissionsTo === 'email' &&
(props.sendSubmissionsToEmail === 'your@email.com' ||
props.sendSubmissionsToEmail === '')

Choose a reason for hiding this comment

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

what if sendSubmissionsToEmail is null or undefined

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Handled it now

state.responseData = body;
state.formState = 'error';

let message = props.errorMessagePath

Choose a reason for hiding this comment

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

Can we create a small function to get the message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code is not repeated anywhere, why do we need a function.

@clyde-builderio
Copy link
Contributor

@anaghav2023 Would it be possible to write a test for this?

if (
props.sendSubmissionsTo === 'email' &&
(props.sendSubmissionsToEmail === 'your@email.com' ||
props.sendSubmissionsToEmail === '')
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
props.sendSubmissionsToEmail === '')
!props.sendSubmissionsToEmail)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pushed changes

if (
props.sendSubmissionsTo === 'email' &&
(props.sendSubmissionsToEmail === 'your@email.com' ||
props.sendSubmissionsToEmail === '')
Copy link
Contributor

Choose a reason for hiding this comment

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

Asking out of curiosity
Are we also responsible to validate if emails are temp emails or an actual email?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, we are not doing that here. The API will send error response

@@ -187,6 +187,21 @@ export default function FormComponent(props: FormProps) {

state.formState = 'sending';

if (
props.sendSubmissionsTo === 'email' &&
(props.sendSubmissionsToEmail === 'your@email.com' ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
(props.sendSubmissionsToEmail === 'your@email.com' ||
const isInvalidEmailConfig = () =>
props.sendSubmissionsTo === 'email' &&
(!props.sendSubmissionsToEmail || props.sendSubmissionsToEmail === 'your@email.com');

we can create a function which can validate input emails

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yash-builder This is actually not the email which comes from the form input. This is the email that users set when creating the form. Since this code is not repeating, I'll let it be

@anaghav2023
Copy link
Contributor Author

anaghav2023 commented Apr 17, 2025

@anaghav2023 Would it be possible to write a test for this?

@clyde-builderio I added a test to check the console errors

@anaghav2023 anaghav2023 reopened this Apr 17, 2025
Comment on lines +51 to +54
test.skip(
excludeTestFor({ reactNative: true, rsc: true }, sdk),
'Form not implemented in React Native and NextJS SDKs.'
);
Copy link
Contributor

@clyde-builderio clyde-builderio Apr 21, 2025

Choose a reason for hiding this comment

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

instead of the current test.skip() try

test.skip(sdk !== 'angular'));

Copy link
Contributor

Choose a reason for hiding this comment

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

is your change only for angular?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@clyde-builderio this change is to address issue in angular SDK. But I think the form.lite.tsx is common for all sdks and I want it to work everywhere.

Copy link
Contributor

@clyde-builderio clyde-builderio Apr 21, 2025

Choose a reason for hiding this comment

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

Then instead of test.skip(sdk !== 'angular');
we can do

test.skip(excludeGen1(sdk));

this will make sure the Gen 1 React SDK tests get skipped
I'll check if there is way to make sure the other Gen 2 tests do not fail

Copy link
Contributor

Choose a reason for hiding this comment

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

If I run yarn g:nx serve @e2e/solid and then hit http://localhost:4173/form in the browser i dont get any console.log() but I get a builder-text below the button
Screenshot 2025-04-21 at 2 05 05 PM

Copy link
Contributor

Choose a reason for hiding this comment

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

Same outcome happens if i run yarn g:nx serve @e2e/solid-start and hit http://localhost:3000/form
Screenshot 2025-04-21 at 2 08 50 PM

Copy link
Contributor

Choose a reason for hiding this comment

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

For the qwik-city failure....looks like a flaky test. Maybe re-running the GitHub check should resolve it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@clyde-builderio Thanks. Thats right for solid sdks somehow the error doesn't get printed on console but shows up on screen. I have updated the test to handle that separately for the solid SDK

@clyde-builderio
Copy link
Contributor

@anaghav2023 Tried using Cursors AI to figure why it's not working

The below test is passing...don't see a major difference except the Promise.all()

test.only('form submission', async ({ page, sdk }) => {
    test.skip(
      excludeTestFor({ reactNative: true, rsc: true }, sdk),
      'Form not implemented in React Native and NextJS SDKs.'
    );

    test.skip(excludeGen1(sdk));

    // Create console listener before clicking submit
    const consoleMessages: string[] = [];
    page.on('console', async msg => {
      // Get all args and convert them to strings
      const args = await Promise.all(msg.args().map(arg => arg.jsonValue()));
      const messageText = args.join(' ');
      consoleMessages.push(messageText);
    });

    await page.goto('/form');

    const form = page.locator('form');
    await expect(form).toHaveCount(1);

    const inputs = await form.locator('input').all();
    await inputs[0].fill('Test Name');
    await inputs[1].fill('test@example.com');
    await page.locator('select').selectOption('20-30');
    await page.locator('textarea').fill('Test message');

    // Submit the form
    await form.locator('button').click();

    // Wait for any console messages to be processed
    await page.waitForTimeout(100);

    // Verify error message was logged
    if (sdk === 'solid') {
      await expect(page.locator('.builder-text').nth(3)).toHaveText(
        'SubmissionsToEmail is required when sendSubmissionsTo is set to email'
      );
    } else {
      expect(
        consoleMessages.some(msg =>
          msg.includes('SubmissionsToEmail is required when sendSubmissionsTo is set to email')
        )
      ).toBeTruthy();
    }
  });

Comment on lines 2 to 3
"@builder.io/sdk": patch
"@builder.io/react": patch
Copy link
Contributor

Choose a reason for hiding this comment

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

These are Gen 1 SDKs. They can be removed from this file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed them

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sidmohanty11 just wanted to confirm with you if a patch update is okay for this change

Copy link
Contributor

Choose a reason for hiding this comment

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

yup should be good!

anaghav2023 and others added 2 commits April 22, 2025 13:59
Co-authored-by: Yash Wadhia <188822535+yash-builder@users.noreply.github.com>
Copy link
Contributor

@clyde-builderio clyde-builderio left a comment

Choose a reason for hiding this comment

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

LGTM

@anaghav2023 anaghav2023 merged commit a1e0f69 into BuilderIO:main Apr 22, 2025
46 checks passed
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.

6 participants