Skip to content

Warning when deleting a split area. #513

Closed

Description

@YevgeniGitin

Describe the bug:
When deleting a split area, the following warning appears in the console:
as-split: Percent areas must total 100%
After reviewing my implementation, I confirmed that the area sizes are set correctly.
In my use case, I always have at least 1 and at most 2 split areas at any given time.

  • When starting with one area or adding a second area, everything works as expected, and no warnings appear.
  • However, when deleting one of the areas, the warning is triggered—even though the remaining area is configured correctly.

Library version:
@angular-split version: "^19.0.0",
angular: 19 (latest).

Steps to reproduce the issue:

I created a demo to reproduce the issue:
Remove area demo

  1. Start with 2 split area.
  2. Delete one of the areas programmatically(by button click).

Observe the warning in the console:
as-split: Percent areas must total 100%

Expected behavior:
Deleting a split area should not result in a warning.

Activity

  1. Harpush commented on May 27, 2025

    @Harpush
    Collaborator

    Most likely related to angular/angular#59067.
    I will try to change the effect to afterRenderEffect and see if it helps

  2. Harpush commented on May 27, 2025

    @Harpush
    Collaborator

    @Jefiozie @SanderElias Three options here:

    1. Use afterRenderEffect which will postpone the check and wait for full render
    2. Introduce a isInit signal like mentioned here (Signal Queries are populated before the input have been set on the components angular/angular#59067 (comment))
    3. Wait with any fix until angular solves the issue on their side

    What do you think?

  3. SanderElias commented on May 28, 2025

    @SanderElias
    Contributor

    @Harpush

    Or, use a simple utility function to deal with this:

    /**
     * utility function to read a signal and return undefined if the signal is not set yet.
     * This is useful to avoid the NG0950 error when reading a signal before it is set.
     * @param data
     * @returns
     */
    export const earlyReadToUndefined = <T>(data: Signal<T>): T | undefined => {
      try {
        return data();
      } catch (err) {
        const e = err as Error;
        if (e?.message?.startsWith('NG0950')) {
          // NG0950: Cannot read from a signal before it is set
          // this is a known error, so we can just return undefined
          // https://angular.io/api/core/NG0950
          return undefined;
        }
        throw e; // rethrow, because we don't know what else to do
      }
    };

    However, that means you need to handle the undefined value in the function that uses that input. In some cases, the afterRenderEffect is easier to deal with. But it is an effect, and should be avoided unless there is no other solution.

  4. Harpush commented on May 28, 2025

    @Harpush
    Collaborator

    @SanderElias this case is a bit different from the linked issue.
    The current validation warning effect has a nested signal access - first the areas content children and then the size of each area.
    The problem is that content children emits as soon as it can - before the inputs settled. That means when removing we have one area with size 50 instead of size 100 and sometime later we get another effect run with the size 100. At this point the warning has already been logged.

    Concerning what you wrote - the size isn't a required input so the error won't be thrown and there is already an effect for the validations warning logging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions