Setting URL alias without '/' prevents all article edits

Created on 7 May 2025, 5 days ago

Overview

When creating a new page within an Article and setting its URL alias without the leading slash (e.g., testpage1 instead of /testpage1), throws an error:
"An unexpected error has occurred while fetching layouts."

This issue not only affects the current page but also prevents editing of any other Article pages, even if the problematic page is deleted.

  1. Edit an existing Article
  2. From the navigator, create a new page and set the title to Test page 1.
  3. In the right-hand section, add a URL alias as testpage1 (Do not add a leading "/").
  4. Observe the error message: "An unexpected error has occurred while fetching layouts."
  5. Try editing any other Article โ€” the error persists.
  6. Even after deleting all existing articles and creating new ones, the issue still remains.

Proposed resolution

User interface changes

๐Ÿ› Bug report
Status

Active

Version

0.0

Component

Page builder

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @mayur-sose
  • Error in browser console

    {
        "message": "assert(str_starts_with($autoSavePath, '/'))"
    }
    
    {
        "status": 500,
        "data": {
            "message": "assert(str_starts_with($autoSavePath, '/'))"
        }
    }
    
  • Below is the code to fix the issue :

    -          assert(str_starts_with($autoSavePath, '/'));
    +          // Ensure autoSavePath starts with '/'
    +          if (!str_starts_with($autoSavePath, '/')) {
    +            $autoSavePath = '/' . ltrim($autoSavePath, '/');
    +          }
    
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia meghasharma
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Akhil Babu Chengannur

    Rather than adding '/' to paths that dont start with it, we should add validation to the entity form fields

    Validation for entity fields are not yet impletemted
    file: experience_builder/ui/src/components/form/inputBehaviors.tsx

      const validateNewValue = (e: React.ChangeEvent, newValue: any) => {
        // @todo Implement this.
        return { valid: true, errors: null };
      };

    This should be updated to

      const validateNewValue = (e: React.ChangeEvent, newValue: any) => {
        const target = e.target as HTMLInputElement;
        if (target.id === 'edit-path-0-alias' && typeof newValue === 'string') {
          if (newValue && !newValue.startsWith('/')) {
            return {
              valid: false,
              errors: [
                {
                  keyword: 'value',
                  instancePath: '',
                  schemaPath: '',
                  params: {},
                  message: 'The alias path has to start with a slash',
                },
              ],
            };
          }
        }
        // @todo Implement for other entity fields.
        return { valid: true, errors: null };
      };
  • Pipeline finished with Failed
    5 days ago
    #491070
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia meghasharma

    Thanks @akhil for the input!
    You're right โ€” adding frontend validation makes sense for better UX and to prevent invalid input early on. I'll update the PR to include this validation inside validateNewValue().

    Also, I think we can keep the backend fallback (str_starts_with) check just to be safe in case any invalid alias somehow bypasses the UI (e.g., via API or future form changes).

    Let me know if you'd prefer removing the backend fallback.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia meghasharma

    Right now Iโ€™ve added backend validation to ensure alias starts with /, which resolves the layout error.
    Also noticed that the error message โ€œThe alias path has to start with a slashโ€ is already being shown in the UI if / is missing โ€” but the page still gets saved.
    Should I go ahead and update the frontend logic to block submission if the alias is invalid?
    Attaching the screenshot.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia meghasharma
  • ๐Ÿ‡ซ๐Ÿ‡ฎFinland lauriii Finland
  • ๐Ÿ‡ซ๐Ÿ‡ฎFinland lauriii Finland

    It looks like it's actually an assert that's triggering this. Changing to major because of that.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia meghasharma
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    @akhil babu in #5:

    Rather than adding '/' to paths that dont start with it, we should add validation to the entity form fields

    ๐Ÿ’ฏ

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia meghasharma
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia meghasharma

    Updated the patch to add client-side validation to ensure alias starts with /.
    However, currently weโ€™re still able to publish even if the alias doesnโ€™t start with /
    Attaching screenshot to show the client-side error.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia meghasharma
  • Pipeline finished with Failed
    3 days ago
    Total: 875s
    #492970
  • ๐Ÿ‡ช๐Ÿ‡ธSpain penyaskito Seville ๐Ÿ’ƒ, Spain ๐Ÿ‡ช๐Ÿ‡ธ, UTC+2 ๐Ÿ‡ช๐Ÿ‡บ

    @meghasharma I'm pretty sure the publish issue is because of ๐Ÿ“Œ Publish checks validation constraints, but not form validation Active , so you shouldn't need to worry about that here.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia meghasharma

    Thanks @penyaskito for the clarification!
    Yes, the client-side validation is now working correctly and shows an error when the alias does not start with /.
    Since the publishing behavior is related to #3521759 and not this issue, Iโ€™m moving this back to Needs review.

Production build 0.71.5 2024