-3

Considering this question about a not-working CSS :first-child selector.


The OP posted a question with a full HTML structure in the question, and later it was edited into an SO Snippet showing that everything was working.

Later, another user edited it again, adding the original code directly into the SO Snippet, making it invalid.


What happened here is that later editing became as follows (invalid HTML):

<html>
    <head>
        <!-- SO Snippet inserted tags -->
    </head>
    <body>
        <!-- Start of pasted question code -->
        <html>
            <head>
            ...

That SO Snippet behaviour sometimes can lead to a wrongly-closed question (can't reproduce, working as intended, etc.).

Maybe SO Snippet should warn that it accepts only <body> content when sees wrong HTML? Or allow to paste the full HTML content to be parsed correctly?

7
  • 1
    "it was edited into SO Snippet showing that everything is working." I'd say this was the first wrong step. Which then lead to other problems. If the code can cleanly be put in as a snippet, then go for it but if it requires changes for the code snippet, then it's better to not do it. Just close as needing MCVE. I also tend to comment pointing to an external snippet site like JSBin.
    – VLAZ
    Nov 9, 2022 at 11:06
  • The transformations may change the semantics of the code. I often see it with JS+HTML code where OP gets an error clearly indicating that the JS code runs before the HTML is rendered (thus tries to access an element before it exists) and somebody comes in, formats it as a snippet and changes the order of evaluation then comments "it works in your code".
    – VLAZ
    Nov 9, 2022 at 11:06
  • 4
    The OP's code works just fine, as you can see in this jsbin snippet using OP's exact code. The editor broke OP's code by incorrectly applying stack snippets.
    – Cerbrus
    Nov 9, 2022 at 11:09
  • @VLAZ Yes, I have seen multiple times it with JS code too. In this particular question it was very clear how to split up into SO Snippet blocks
    – Justinas
    Nov 9, 2022 at 11:09
  • @Cerbrus Can we just fork JS Bin code to replace with SO Snippet? :D
    – Justinas
    Nov 9, 2022 at 11:10
  • @Justinas right, I started writing the comment for a reason then...never actually got to it. One important reason not to do it is that it invites other people to edit the snippet to "make it better" or something. And that might break stuff. Yes, I agree your edit had the correct semantics, thus did prove that OP's code didn't behave like OP claimed, but it's really up to the question asker to provide an example that is representative. Even when the code is transformed correctly for the snippet, one fact remains: that's not the problematic code. Making it runnable doesn't clarify anything.
    – VLAZ
    Nov 9, 2022 at 11:13
  • "an we just fork JS Bin code to replace with SO Snippet?" as a frequent JSBin user, I can tell you that the grass is not greener. Yes, JSBin handles full HTML documents more correct than StackSnippets do, but JSBin has other subtle differences in behaviour that you'd need to navigate around. Example where it turns out protection from infinite loops also stops dead loops that are finite but slightly too slow. No snippet service is exactly like a full HTML document, I've seen SO questions about stuff only present on, say JSFiddle or CodePen, etc.
    – VLAZ
    Nov 9, 2022 at 11:18

1 Answer 1

3

For obviously wrong usage, such as body / html tags in the html block, validation would be very helpful.

As it is now, the stack snippet can be submitted, but actually breaks, potentially leading well-intending users to incorrect conclusions.

I always like checking my snippets on an external source that works on "raw source html" for lack of a better word.
For this specific case, I doublechecked in JSBin to verify that the OP's code did indeed work the same way as it does when converted to a snippet.

The edited snippet that pasted all of the OP's sourcecode into the HTML block did indeed break the snippet.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .