Visitar URL original
Restore frontend router after loading member form libraries by robinsowell · Pull Request #5350 · ExpressionEngine/ExpressionEngine · GitHub
Skip to content

Restore frontend router after loading member form libraries - #5350

Open
robinsowell wants to merge 1 commit into
7.devfrom
bugfix/member-edit
Open

robinsowell wants to merge 1 commit into
7.devfrom
bugfix/member-edit

Conversation

@robinsowell

Copy link
Copy Markdown
Contributor

Prevent member edit and registration tags from leaving the router in the control panel context, which can break subsequent frontend layout parsing. Add regression coverage for both forms.

Why this matters

The router is shared for the entire request. These frontend Member tags temporarily change it to cp so they can load Control Panel form libraries:

  • {exp:member:edit_profile}
  • {exp:member:registration_form}

Previously, they never changed it back. Anything parsed after the tag could therefore incorrectly believe it was running inside the Control Panel.

For example:

{layout="site:_layouts/wrapper"}

{exp:member:edit_profile}
    {field:company_name}
{/exp:member:edit_profile}

After rendering the member form, ExpressionEngine still reported the router class as cp. This could interfere with subsequent layout and template processing, especially on an MSM installation.
Observed symptoms included:
Nested layouts failing with Template Not Found, resulting in a blank page.

Site-specific template variables remaining unparsed, such as:

{var_licenses-table_styles_2024}
When this unresolved variable was placed in <head>, the browser moved the text into <body>, causing it to appear visibly above the site header.

Other code executed later in the request—including add-ons and extensions—could also choose the wrong behavior if it checks the router to distinguish frontend and Control Panel requests.
The fix records the original router class, temporarily switches to cp, loads the required libraries, and then restores the original value. It restores rather than hard-codes ee, preserving whichever context initiated the request.

{var_licenses-table_styles_2024}

When this unresolved variable was placed in <head>, the browser moved the text into <body>, causing it to appear visibly above the site header.

Other code executed later in the request—including add-ons and extensions—could also choose the wrong behavior if it checks the router to distinguish frontend and Control Panel requests.

The fix records the original router class, temporarily switches to cp, loads the required libraries, and then restores the original value. It restores rather than hard-codes ee, preserving whichever context initiated the request.

## Longer-term fix

Frontend Member forms should not need to mutate the global router to load field rendering and JavaScript dependencies. The shared form functionality should be extracted from the CP-only library or made explicitly usable in a frontend context.

That would remove the temporary `cp` masquerade entirely. The save-and-restore change in this PR is a safe short-term fix while preserving the existing library behavior.

Prevent member edit and registration tags from leaving the router in the control panel context, which can break subsequent frontend layout parsing. Add regression coverage for both forms.
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.

1 participant