Repository: reflex-dev/reflex
Pull request: Fixed unused kwargs in reflex.App
### Type of change
- [x] Bug fix (non-breaking change which fixes an issue)

Fixed kwargs `sio` and `socket_app` are not used during reflex.App initialization

Closes #3081



Problem statement:
Entering more than 999775 characters breaks text_area
**Describe the bug**
Entering more than 999775 characters breaks rx.text_area. If you enter more than 999775 characters into a text area you will have to refresh the page for the text_area to work again.

**To Reproduce**
Steps to reproduce the behavior:

```
import reflex as rx
import pyperclip

class State(rx.State):

    def print_length(self, value: str):
        print(len(value))

    def copy_to_clipboard(text_length):
        # Copy 'text_length' number of 'a's to the clipboard
        text_length = 999776    # Fails
        # text_length = 999775  # Works
        text = 'a' * text_length
        pyperclip.copy(text)
        print(f"Copied {text_length} characters to the clipboard.")

def index() -> rx.Component:
    return rx.center(
        rx.text_area(
            on_change=State.print_length,
            height="50vh",
            width="50vw",
        ),
        height="100vh",
    )

app = rx.App()
app.add_page(index, on_load=State.copy_to_clipboard)
```

**Expected behavior**
The text area should behave the same way that it does when you enter less than 999776 characters.

**Specifics (please complete the following information):**
 - Python Version: 3.11.6
 - Reflex Version: 0.4.7
 - OS: Ubuntu 23.10
 - Browser (Optional): Chrome & Firefox

Hints from issue discussion:

Commit message: Fixed unused kwargs in reflex.App

Patch to review:
diff --git a/reflex/app.py b/reflex/app.py
index c47077d0ef8..dcd7ef742a1 100644
--- a/reflex/app.py
+++ b/reflex/app.py
@@ -223,21 +223,24 @@ def setup_state(self) -> None:
         self._state_manager = StateManager.create(state=self.state)
 
         # Set up the Socket.IO AsyncServer.
-        self.sio = AsyncServer(
-            async_mode="asgi",
-            cors_allowed_origins=(
-                "*"
-                if config.cors_allowed_origins == ["*"]
-                else config.cors_allowed_origins
-            ),
-            cors_credentials=True,
-            max_http_buffer_size=constants.POLLING_MAX_HTTP_BUFFER_SIZE,
-            ping_interval=constants.Ping.INTERVAL,
-            ping_timeout=constants.Ping.TIMEOUT,
-        )
+        if not self.sio:
+            self.sio = AsyncServer(
+                async_mode="asgi",
+                cors_allowed_origins=(
+                    "*"
+                    if config.cors_allowed_origins == ["*"]
+                    else config.cors_allowed_origins
+                ),
+                cors_credentials=True,
+                max_http_buffer_size=constants.POLLING_MAX_HTTP_BUFFER_SIZE,
+                ping_interval=constants.Ping.INTERVAL,
+                ping_timeout=constants.Ping.TIMEOUT,
+            )
 
         # Create the socket app. Note event endpoint constant replaces the default 'socket.io' path.
-        self.socket_app = ASGIApp(self.sio, socketio_path="")
+        if not self.socket_app:
+            self.socket_app = ASGIApp(self.sio, socketio_path="")
+
         namespace = config.get_event_namespace()
 
         # Create the event namespace and attach the main app. Not related to any paths.


Code review comments:
diff_hunk: @@ -223,21 +223,24 @@ def setup_state(self) -> None:
         self._state_manager = StateManager.create(state=self.state)
 
         # Set up the Socket.IO AsyncServer.
-        self.sio = AsyncServer(
-            async_mode="asgi",
-            cors_allowed_origins=(
-                "*"
-                if config.cors_allowed_origins == ["*"]
-                else config.cors_allowed_origins
-            ),
-            cors_credentials=True,
-            max_http_buffer_size=constants.POLLING_MAX_HTTP_BUFFER_SIZE,
-            ping_interval=constants.Ping.INTERVAL,
-            ping_timeout=constants.Ping.TIMEOUT,
-        )
+        if not self.sio:
+            self.sio = AsyncServer(
+                async_mode="asgi",
+                cors_allowed_origins=(
+                    "*"
+                    if config.cors_allowed_origins == ["*"]
+                    else config.cors_allowed_origins
+                ),
+                cors_credentials=True,
+                max_http_buffer_size=constants.POLLING_MAX_HTTP_BUFFER_SIZE,
+                ping_interval=constants.Ping.INTERVAL,
+                ping_timeout=constants.Ping.TIMEOUT,
+            )
 
         # Create the socket app. Note event endpoint constant replaces the default 'socket.io' path.
-        self.socket_app = ASGIApp(self.sio, socketio_path="")
+        if not self.socket_app:
+            self.socket_app = ASGIApp(self.sio, socketio_path="")
path: reflex/app.py
text: @user1:
i think we should actually remove the `socket_app` from the app args and just use a local variable here.

1. there aren't really any args that the user would want/need to configure on this interface
2. it's not possible to use without also passing `sio`
3. it's not used anywhere else in reflex, so there's no real reason to keep a reference of it on the class after mounting it via fastapi.