when i move things in canvas, the new position is not saved
- User
when i move things in canvas, the new position is not saved
Assistant
Let me look at the canvas-related code to understand the issue.
Assistant
The JS correctly calls
saveComponentPositionon mouse up, which PATCHes/api/pages/:pageId/components/:componentId. Let me check the server-side PATCH route.Assistant
The PATCH route looks like it should work. Let me check how components are rendered — the issue might be that saved positions aren't applied when the page reloads.
Assistant
Found the bug. In the PATCH route at
web/app.rb:566,r.body.readconsumes the request body stream for JSON parsing. When that fails (because the JS sends URL-encoded form data, not JSON), it falls back tor.params— but the stream is already consumed, sor.paramsreturns empty and nothing gets saved.Assistant
The fix: after reading the body for JSON parsing,
r.body.rewindresets the stream sor.paramscan read it when JSON parsing fails.The same pattern exists for the POST route — let me check if it's also affected.
Assistant
The POST route at line 524 has the same issue, though it happens to work because the JS
createComponentmethod sends JSON withContent-Type: application/json. Still, worth fixing for consistency.Assistant
The bug:
r.body.readconsumes the Rack input stream. WhenJSON.parsefails (becausesaveComponentPositionsendsapplication/x-www-form-urlencoded, not JSON), therescuefalls back tor.params. But since the stream is already consumed,r.paramscan't parse the POST body and returns an empty hash — so x/y are never updated.The fix:
r.body.rewindafter reading resets the stream sor.paramscan parse it correctly in the fallback path.- User
commit this
Assistant
Committed as
27820b4.