Need help with the basics on serial control
You are assuming that Serial.readString() will magically know how long a string you meant to send, and wait until it's all there.  It doesn't guarantee that.

If your PC uses Linux or Mac, you can use Serial.readStringUntil('\n'), which will read until a line end, and send on&lt;ENTER&gt; as your command.

If you use Windows, the line endings are \r\n so it's a bit more awkward.  Build up your string piece by piece, perhaps

int relay=8;
String serialInput;

void setup() {
  Serial.begin(9600);
  pinMode(relay, OUTPUT);
}

void loop() {
  if (Serial.available()) {
    char c = Serial.read();   // get one byte from serial buffer
    if ('\r'==c || '\n'==c) {
      // End of line - process the string
      if(serialInput=="on") {
        digitalWrite(relay, HIGH);
      } else if (serialInput=="off") {
        digitalWrite(relay, LOW);
      }
      serialInput = "";
    } else {
      serialInput += c;     // add it to readString
    }
  }
}


Brief description of how it works:

The string SerialInput starts empty.  We do the following repeatedly:


If there is a character available on the serial port, read it.
If it is not an end-of-line character, add it to the end of our string
If it IS an end-of-line character, we know we've got to the end of the line, so...


check whether it matches one of our "target" strings, and act on it if so
clear it back to an empty string