Reseting robots.txt override doesn't seem to work as expected

AI-generated summary

The issue concerns the ‘Reset’ button in the /admin/customize/robots page, which is intended to restore the default robots.txt. When clicked, the form is incorrectly filled with the website’s HTML code and appears to save it immediately, though a refresh shows the default robots.txt is actually applied. mentalstring reports this behavior, noting the reset button should ideally restore initial values without submitting. Arkshine confirms the issue, identifying the root cause in the render_to_string method rendering the template with a default layout. A fix is proposed by adding layout: false to the render call. Osama confirms the issue has been resolved in commit 87883a1, crediting both reporters.

It’s possible to override robots.txt in /admin/customize/robots (which is linked in the settings). The page provides a form to have a custom robots.txt. Example:

When pressing that ‘Reset’ button however, the form is immediately filled with what seems to be the website’s own html code and… appears to immediately save that as the new robots.txt

After a refresh however, it seems to actually have the Discourse’s default robots.txt, so it was reset to the default. But still, that filling with html probably needs a look.

On that note, form reset buttons usually restore the form to initial values (and don’t immediately submit the form), so maybe a “Restore to default robots.txt” link next to the buttons would be more clear.

3 Likes

I can reproduce as well!


To devs: The issue concerns render_to_string that renders the template with a default layout. :thinking:

Here is a solution: adding , layout: false param. :point_up_2:

4 Likes

This should be fixed in:

https://github.com/discourse/discourse/commit/87883a1963236e919854914b0a02ab1496bb3334

Thanks @mentalstring for the report and @Arkshine for pointing out where the problem is!

4 Likes

This topic was automatically closed after 41 hours. New replies are no longer allowed.