How to fix a malformed page

We recently discovered an issue where pages with multiple <html>, <head>, or <body> tags could get published incorrectly. As you probably know, the HTML spec only allows each of these elements to appear once in a single page. However, in some circumstances pages end up with duplicates. This results in a malformed page.

Fortunately, browsers are very tolerant of bad markup and don’t bother to tell you when there’s an extra tag or two in your code. They just fix it and move on. This is great for your visitors, but Surreal can’t be quite as forgiving.

You see, browsers only need to parse and display your page. Surreal, on the other hand, needs to parse, display, update, and then publish changes back to it. While we try to make our service as resilient as possible, there are technical issues with malformed pages that often lead to publishing errors.

To ensure your pages publish properly every time, we added a check to notify you when a page is malformed. Here’s what it looks like in the editor:

Malformed page error
A malformed page error

How to fix it

If you see this message, check the source for duplicate <html>, <head>, and <body> tags. If you don’t see any in the source, check your include files. Chances are, they’re being pulled in when the page is rendered. Once you find the duplicates, simply remove them to fix the problem.

If you’re having a hard time finding what’s causing this error, consider running your page through the HTML validator. It’s a great tool for identifying errors in your markup.

But it worked before

Up until today, Surreal would not notify you when it came across a malformed page. It just trudged through and did its best to publish your pages. In some cases, publishing would work as expected. In many cases, it wouldn’t.

Despite our efforts, we realized that it’s simply not possible to reliably determine if a malformed page will publish properly or not. As a result, you might all of a sudden see this error even if you’ve been editing your site in Surreal for a long time.

The good news is that it’s usually easy to fix—and once you do, browsers, search engines, and anything else that parses your page will be forever grateful!