I have a module that uses ajax to post back to the server for data. Some of this data is configurable while in experience editor. Users are winding up in a state with this module where experience editor html is showing up while in normal mode. The steps to get to this are as follows
- The user visits the page with the module in normal mode
- The user then opens a different tab/window in the same browser and opens experience editor mode
- The user then goes back to the original tab and clicks one of the buttons that makes an ajax call. The resulting rendered fields are rendered for experience editor and that excess html is rendered as plain text
Currently to work around this I added a flag on a data attribute called
data-enforce-normal-mode. When that is set to true I pass along that flag with my ajax response. I then wrap my original code in the following which causes the html to render as though it wasn't in experience editor mode:
This feels like a hack. A longer routed alternative is to pass the enforce bool to the service which gets my return object and use the field renderer with
disable-web-editing=true for every field when the bool is set to true but that sounds tedious and hard to maintain in the future due to any new editable field needing this pattern. Is there a better way to maintain the state that my page is in so that if a page is accessed by a user that isn't logged in the ajax request will have the correct context for this?