Skip to content

Commit 21391a7

Browse files
committed
make things better
1 parent fa9f32e commit 21391a7

File tree

22 files changed

+66
-60
lines changed

22 files changed

+66
-60
lines changed

exercises/03.complex/04.problem.dynamic-sizing/README.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
👨‍💼 Users expect iframes to fit their content perfectly, not waste space or require scrolling. The journal viewer should automatically adjust to show exactly what's needed.
44

55
```tsx
6-
const height = document.documentElement.scrollHeight
7-
const width = document.documentElement.scrollWidth
6+
const height = document.documentElement.clientHeight
7+
const width = document.documentElement.clientWidth
88

99
window.parent.postMessage(
1010
{
@@ -15,7 +15,7 @@ window.parent.postMessage(
1515
)
1616
```
1717

18-
Use `scrollHeight` and `scrollWidth` to measure the full content dimensions, then send a `ui-size-change` message to the parent window so it can resize the iframe accordingly.
18+
Use `clientHeight` and `clientWidth` to measure the full content dimensions, then send a `ui-size-change` message to the parent window so it can resize the iframe accordingly.
1919

2020
The static `preferred-frame-size` from the previous exercise works for fixed layouts, but journal entries have varying content lengths. A short entry wastes space, while a long entry gets cut off.
2121

exercises/03.complex/04.problem.dynamic-sizing/app/routes/ui/journal-viewer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ export default function JournalViewer({ loaderData }: Route.ComponentProps) {
3434
// 💰 const root = rootRef.current
3535
// 🐨 if the root is null, return
3636
// 🐨 get the height and width of the root
37-
// 💰 const height = root.scrollHeight
38-
// 💰 const width = root.scrollWidth
37+
// 💰 const height = root.clientHeight
38+
// 💰 const width = root.clientWidth
3939
// 🐨 call window.parent.postMessage with the type 'ui-size-change' and the payload { height, width }
4040
// 🐨 set the targetOrigin to '*'
4141
}, [])

exercises/03.complex/04.solution.dynamic-sizing/app/routes/ui/journal-viewer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ export default function JournalViewer({ loaderData }: Route.ComponentProps) {
2525
const root = rootRef.current
2626
if (!root) return
2727

28-
const height = root.scrollHeight
29-
const width = root.scrollWidth
28+
const height = root.clientHeight
29+
const width = root.clientWidth
3030

3131
window.parent.postMessage(
3232
{ type: 'ui-size-change', payload: { height, width } },

exercises/04.interactive/01.problem.links/app/routes/ui/journal-viewer.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ export default function JournalViewer({ loaderData }: Route.ComponentProps) {
3030
}
3131

3232
return (
33-
<div className="bg-background max-h-[800px] overflow-y-auto p-4">
33+
<div
34+
ref={rootRef}
35+
className="bg-background max-h-[800px] overflow-y-auto p-4"
36+
>
3437
<div className="mx-auto max-w-4xl">
3538
<div className="bg-card mb-6 rounded-xl border p-6 shadow-lg">
3639
<h1 className="text-foreground mb-2 text-3xl font-bold">

exercises/04.interactive/01.problem.links/app/utils/mcp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ export function useMcpUiInit(rootRef: React.RefObject<HTMLDivElement | null>) {
55
window.parent.postMessage({ type: 'ui-lifecycle-iframe-ready' }, '*')
66
if (!rootRef.current) return
77

8-
const height = rootRef.current.scrollHeight
9-
const width = rootRef.current.scrollWidth
8+
const height = rootRef.current.clientHeight
9+
const width = rootRef.current.clientWidth
1010

1111
window.parent.postMessage(
1212
{ type: 'ui-size-change', payload: { height, width } },

exercises/04.interactive/01.solution.links/app/utils/mcp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ export function useMcpUiInit(rootRef: React.RefObject<HTMLDivElement | null>) {
55
window.parent.postMessage({ type: 'ui-lifecycle-iframe-ready' }, '*')
66
if (!rootRef.current) return
77

8-
const height = rootRef.current.scrollHeight
9-
const width = rootRef.current.scrollWidth
8+
const height = rootRef.current.clientHeight
9+
const width = rootRef.current.clientWidth
1010

1111
window.parent.postMessage(
1212
{ type: 'ui-size-change', payload: { height, width } },

exercises/04.interactive/02.problem.tools/app/utils/mcp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export function useMcpUiInit(rootRef: React.RefObject<HTMLDivElement | null>) {
66
window.parent.postMessage({ type: 'ui-lifecycle-iframe-ready' }, '*')
77
if (!rootRef.current) return
88

9-
const height = rootRef.current.scrollHeight
10-
const width = rootRef.current.scrollWidth
9+
const height = rootRef.current.clientHeight
10+
const width = rootRef.current.clientWidth
1111

1212
window.parent.postMessage(
1313
{ type: 'ui-size-change', payload: { height, width } },

exercises/04.interactive/02.problem.tools/worker/mcp/tools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ export async function initializeTools(agent: EpicMeMCP) {
460460
},
461461
async ({ id }) => {
462462
const iframeUrl = new URL(
463-
'/ui/entry-viewer/${id}',
463+
`/ui/entry-viewer/${id}`,
464464
agent.requireBaseUrl(),
465465
)
466466

exercises/04.interactive/02.solution.tools/app/utils/mcp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export function useMcpUiInit(rootRef: React.RefObject<HTMLDivElement | null>) {
66
window.parent.postMessage({ type: 'ui-lifecycle-iframe-ready' }, '*')
77
if (!rootRef.current) return
88

9-
const height = rootRef.current.scrollHeight
10-
const width = rootRef.current.scrollWidth
9+
const height = rootRef.current.clientHeight
10+
const width = rootRef.current.clientWidth
1111

1212
window.parent.postMessage(
1313
{ type: 'ui-size-change', payload: { height, width } },

exercises/04.interactive/02.solution.tools/worker/mcp/tools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ export async function initializeTools(agent: EpicMeMCP) {
460460
},
461461
async ({ id }) => {
462462
const iframeUrl = new URL(
463-
'/ui/entry-viewer/${id}',
463+
`/ui/entry-viewer/${id}`,
464464
agent.requireBaseUrl(),
465465
)
466466

0 commit comments

Comments
 (0)