Skip to content

Commit 8d17c52

Browse files
authored
Remove editor toolbar and concurrent updates code (unshipping for v1) (#1244)
1 parent 0939afa commit 8d17c52

File tree

14 files changed

+7
-224
lines changed

14 files changed

+7
-224
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,6 @@ jobs:
6464
name: playwright-report-concurrency
6565
path: playwright-report-concurrency/
6666
retention-days: 30
67-
- name: Run playwright test with concurrent updates enabled
68-
run: MESOP_CONCURRENT_UPDATES_ENABLED=true PLAYWRIGHT_HTML_OUTPUT_DIR=playwright-report-with-concurrent-updates-enabled yarn playwright test
69-
- uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0
70-
if: always()
71-
with:
72-
name: playwright-report-with-concurrent-updates-enabled
73-
path: playwright-report-with-concurrent-updates-enabled/
74-
retention-days: 30
7567
- name: Run playwright test with websockets enabled
7668
run: MESOP_WEBSOCKETS_ENABLED=true PLAYWRIGHT_HTML_OUTPUT_DIR=playwright-report-with-websockets-enabled yarn playwright test
7769
- uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4.6.0

docs/api/config.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ These configuration values are experimental and are subject to breaking change,
245245

246246
!!! danger "Deprecated experimental feature"
247247

248-
This experimental feature is deprecated and will be removed in an upcoming release. Use `MESOP_WEBSOCKETS_ENABLED` instead.
248+
This experimental feature has been removed in Mesop v1. Use `MESOP_WEBSOCKETS_ENABLED` instead.
249249

250250
Allows concurrent updates to state in the same session. If this is not updated, then updates are queued and processed sequentially.
251251

mesop/env/env.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
# working directory.
1313
load_dotenv(find_dotenv(usecwd=True))
1414

15-
16-
AI_SERVICE_BASE_URL = os.environ.get(
17-
"MESOP_AI_SERVICE_BASE_URL", "http://localhost:43234"
18-
)
19-
2015
MESOP_APP_BASE_PATH = os.environ.get("MESOP_APP_BASE_PATH", "")
2116
if MESOP_APP_BASE_PATH:
2217
if not os.path.isabs(MESOP_APP_BASE_PATH):
@@ -42,15 +37,3 @@ def get_app_base_path() -> str:
4237
MESOP_WEBSOCKETS_ENABLED = (
4338
os.environ.get("MESOP_WEBSOCKETS_ENABLED", "false").lower() == "true"
4439
)
45-
46-
MESOP_CONCURRENT_UPDATES_ENABLED = (
47-
os.environ.get("MESOP_CONCURRENT_UPDATES_ENABLED", "false").lower() == "true"
48-
)
49-
50-
if MESOP_WEBSOCKETS_ENABLED:
51-
MESOP_CONCURRENT_UPDATES_ENABLED = True
52-
53-
54-
EXPERIMENTAL_EDITOR_TOOLBAR_ENABLED = (
55-
os.environ.get("MESOP_EXPERIMENTAL_EDITOR_TOOLBAR", "false").lower() == "true"
56-
)

mesop/server/server.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
import mesop.protos.ui_pb2 as pb
1717
from mesop.component_helpers import diff_component
1818
from mesop.env.env import (
19-
EXPERIMENTAL_EDITOR_TOOLBAR_ENABLED,
2019
MESOP_APP_BASE_PATH,
21-
MESOP_CONCURRENT_UPDATES_ENABLED,
2220
MESOP_PROD_UNREDACTED_ERRORS,
2321
MESOP_WEBSOCKETS_ENABLED,
2422
)
@@ -48,13 +46,7 @@ def configure_flask_app(
4846
*, prod_mode: bool = True, exceptions_to_propagate: Sequence[type] = ()
4947
) -> Flask:
5048
if MESOP_WEBSOCKETS_ENABLED:
51-
logger.info(
52-
"Experiment enabled: MESOP_WEBSOCKETS_ENABLED (auto-enables MESOP_CONCURRENT_UPDATES_ENABLED)"
53-
)
54-
elif MESOP_CONCURRENT_UPDATES_ENABLED:
55-
logger.info("Experiment enabled: MESOP_CONCURRENT_UPDATES_ENABLED")
56-
if EXPERIMENTAL_EDITOR_TOOLBAR_ENABLED:
57-
logger.info("Experiment enabled: EXPERIMENTAL_EDITOR_TOOLBAR_ENABLED")
49+
logger.info("Experiment enabled: MESOP_WEBSOCKETS_ENABLED")
5850

5951
if MESOP_APP_BASE_PATH:
6052
logger.info(f"MESOP_APP_BASE_PATH set to {MESOP_APP_BASE_PATH}")

mesop/server/server_debug_routes.py

Lines changed: 0 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,11 @@
1-
import inspect
2-
import json
31
import time
4-
from urllib import request as urllib_request
5-
from urllib.error import URLError
62

73
from flask import Flask, Response, request
84

9-
from mesop.env.env import AI_SERVICE_BASE_URL
105
from mesop.runtime import runtime
11-
from mesop.server.server_utils import (
12-
check_editor_access,
13-
make_sse_response,
14-
sse_request,
15-
)
166

177

188
def configure_debug_routes(flask_app: Flask):
19-
@flask_app.route("/__editor__/commit", methods=["POST"])
20-
def page_commit() -> Response:
21-
check_editor_access()
22-
23-
try:
24-
data = request.get_json()
25-
except json.JSONDecodeError:
26-
return Response("Invalid JSON format", status=400)
27-
code = data.get("code")
28-
path = data.get("path")
29-
page_config = runtime().get_page_config(path=path)
30-
assert page_config
31-
module = inspect.getmodule(page_config.page_fn)
32-
assert module
33-
module_file = module.__file__
34-
assert module_file
35-
module_file_path = module.__file__
36-
assert module_file_path
37-
with open(module_file_path, "w") as file:
38-
file.write(code)
39-
40-
response_data = {"message": "Page commit successful"}
41-
return Response(
42-
json.dumps(response_data), status=200, mimetype="application/json"
43-
)
44-
45-
@flask_app.route("/__editor__/save-interaction", methods=["POST"])
46-
def save_interaction() -> Response | dict[str, str]:
47-
check_editor_access()
48-
49-
data = request.get_json()
50-
if not data:
51-
return Response("Invalid JSON data", status=400)
52-
53-
try:
54-
req = urllib_request.Request(
55-
AI_SERVICE_BASE_URL + "/save-interaction",
56-
data=json.dumps(data).encode("utf-8"),
57-
headers={"Content-Type": "application/json"},
58-
)
59-
with urllib_request.urlopen(req) as response:
60-
if response.status == 200:
61-
folder = json.loads(response.read().decode("utf-8"))["folder"]
62-
return {"folder": folder}
63-
else:
64-
print(f"Error from AI service: {response.read().decode('utf-8')}")
65-
return Response(
66-
f"Error from AI service: {response.read().decode('utf-8')}",
67-
status=500,
68-
)
69-
except URLError as e:
70-
return Response(f"Error making request to AI service: {e!s}", status=500)
71-
72-
@flask_app.route("/__editor__/generate", methods=["POST"])
73-
def page_generate():
74-
check_editor_access()
75-
76-
try:
77-
data = request.get_json()
78-
except json.JSONDecodeError:
79-
return Response("Invalid JSON format", status=400)
80-
if not data:
81-
return Response("Invalid JSON data", status=400)
82-
83-
prompt = data.get("prompt")
84-
if not prompt:
85-
return Response("Missing 'prompt' in JSON data", status=400)
86-
87-
path = data.get("path")
88-
page_config = runtime().get_page_config(path=path)
89-
90-
line_number = data.get("lineNumber")
91-
assert page_config
92-
module = inspect.getmodule(page_config.page_fn)
93-
if module is None:
94-
return Response("Could not retrieve module source code.", status=500)
95-
module_file = module.__file__
96-
assert module_file
97-
with open(module_file) as file:
98-
source_code = file.read()
99-
print(f"Source code of module {module.__name__}:")
100-
101-
def generate():
102-
try:
103-
for event in sse_request(
104-
AI_SERVICE_BASE_URL + "/adjust-mesop-app",
105-
{"prompt": prompt, "code": source_code, "lineNumber": line_number},
106-
):
107-
if event.get("type") == "end":
108-
sse_data = {
109-
"type": "end",
110-
"prompt": prompt,
111-
"path": path,
112-
"beforeCode": source_code,
113-
"afterCode": event["code"],
114-
"diff": event["diff"],
115-
"message": "Prompt processed successfully",
116-
}
117-
yield f"data: {json.dumps(sse_data)}\n\n"
118-
break
119-
elif event.get("type") == "progress":
120-
sse_data = {"data": event["data"], "type": "progress"}
121-
yield f"data: {json.dumps(sse_data)}\n\n"
122-
elif event.get("type") == "error":
123-
sse_data = {"error": event["error"], "type": "error"}
124-
yield f"data: {json.dumps(sse_data)}\n\n"
125-
break
126-
else:
127-
raise Exception(f"Unknown event type: {event}")
128-
except Exception as e:
129-
sse_data = {
130-
"error": "Could not connect to AI service: " + str(e),
131-
"type": "error",
132-
}
133-
yield f"data: {json.dumps(sse_data)}\n\n"
134-
135-
return make_sse_response(generate())
136-
1379
@flask_app.route("/__hot-reload__")
13810
def hot_reload() -> Response:
13911
counter = int(request.args["counter"])

mesop/server/server_utils.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
from typing import Any, Generator, Iterable
77
from urllib import request as urllib_request
88

9-
from flask import Response, abort, request
9+
from flask import Response
1010
from werkzeug.security import safe_join
1111

1212
import mesop.protos.ui_pb2 as pb
13-
from mesop.env.env import EXPERIMENTAL_EDITOR_TOOLBAR_ENABLED, get_app_base_path
13+
from mesop.env.env import get_app_base_path
1414
from mesop.exceptions import MesopDeveloperException
1515
from mesop.runtime import runtime
1616
from mesop.server.config import app_config
@@ -25,18 +25,6 @@
2525
STREAM_END = "data: <stream_end>\n\n"
2626

2727

28-
def check_editor_access():
29-
if not EXPERIMENTAL_EDITOR_TOOLBAR_ENABLED:
30-
abort(403) # Throws a Forbidden Error
31-
# Prevent accidental usages of editor mode outside of
32-
# one's local computer
33-
if request.remote_addr not in LOCALHOSTS:
34-
abort(403) # Throws a Forbidden Error
35-
# Visual editor should only be enabled in debug mode.
36-
if not runtime().debug_mode:
37-
abort(403) # Throws a Forbidden Error
38-
39-
4028
def serialize(response: pb.UiResponse) -> str:
4129
encoded = base64.b64encode(response.SerializeToString()).decode("utf-8")
4230
return f"data: {encoded}\n\n"

mesop/server/static_file_serving.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
from werkzeug.security import safe_join
1515

1616
from mesop.env.env import (
17-
EXPERIMENTAL_EDITOR_TOOLBAR_ENABLED,
18-
MESOP_CONCURRENT_UPDATES_ENABLED,
1917
MESOP_WEBSOCKETS_ENABLED,
2018
get_app_base_path,
2119
)
@@ -86,8 +84,6 @@ def retrieve_index_html() -> io.BytesIO | str:
8684
):
8785
experiment_settings = {
8886
"websocketsEnabled": MESOP_WEBSOCKETS_ENABLED,
89-
"concurrentUpdatesEnabled": MESOP_CONCURRENT_UPDATES_ENABLED,
90-
"experimentalEditorToolbarEnabled": EXPERIMENTAL_EDITOR_TOOLBAR_ENABLED,
9187
}
9288
lines[i] = f"""
9389
<script nonce="{g.csp_nonce}">

mesop/tests/e2e/concurrent_updates_test.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

mesop/tests/e2e/e2e_helpers.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,6 @@ export const testInProdOnly = base.extend({
1010
},
1111
});
1212

13-
export const testInConcurrentUpdatesEnabledOnly = base.extend({
14-
// Skip this test if MESOP_CONCURRENT_UPDATES_ENABLED is not 'true'
15-
page: async ({page}, use) => {
16-
if (process.env.MESOP_CONCURRENT_UPDATES_ENABLED !== 'true') {
17-
base.skip(true, 'Skipping test in concurrent updates disabled mode');
18-
}
19-
await use(page);
20-
},
21-
});
22-
2313
export const testInWebSocketsEnabledOnly = base.extend({
2414
// Skip this test if MESOP_WEBSOCKETS_ENABLED is not 'true'
2515
page: async ({page}, use) => {

mesop/web/src/services/channel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,8 @@ export class Channel {
426426
initUserEvent();
427427
} else {
428428
this.queuedEvents.push(initUserEvent);
429-
if (this.experimentService.concurrentUpdatesEnabled) {
430-
// We will wait 1 second to see if the server will respond with a new state.
429+
if (this.experimentService.websocketsEnabled) {
430+
// We will wait a bit to see if the server will respond with a new state.
431431
// This addresses common use cases where a user may
432432
// type in a text input and then click a button and
433433
// they would expect the updated text input state to be

0 commit comments

Comments
 (0)