Gutenberg: how to hide server side render output in the editor but keep it in frontend?

This can be down in the php render_function. Check if it is an API REST request:

function create_block() {
    register_block_type( __DIR__ ,[
        'render_callback' => 'render_php'
    ] );
}

function render_php(){
    

    if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
        return "<p>Backend says hello from php</p>";
    } else {
        return "<p>Frontend says hello from php</p>";
    };

    
}