Skip to content

Commit b63abfa

Browse files
committed
fix(resources): apply CSS transform trickery only to Wixsite
This commit should resolve most of the questions of why we need so much code for a single iframe scenario, as we typically assume all websites adhere to responsive designs. To be fair, WordPress link we received does, but just not for the wixsite link. Unfortunately, we kind of entered a local maximum and decided to fix everything ourselves (a wiser way would be asking the wixsite owner for the account and optimizing on that side). Therefore, we disable the tricks on the WordPress website, as it is responsive by design. Left a TODO to explain this big pile of code/logic just for this very edge-case scenario.
1 parent 9bcbd2f commit b63abfa

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,6 @@ next-env.d.ts
4545

4646
# semi-auto generated diff file
4747
commit.txt
48+
49+
# folder for storing testing files
50+
.testing

src/app/resources/[slug]/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export default async function ResourceEmbedPage({ params }: { params: Promise<{
2828
title={resource.title}
2929
websiteUrl={resource.websiteUrl}
3030
hideTopPx={resource.hideTopPx}
31+
scale={resource.scale}
3132
hideHeader
3233
showOnMobile
3334
containerHeight="100dvh"

src/components/sections/resource-iframe.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,24 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
66
import { cn, isInternalHref, noReturnDebounce } from "@/lib/utils";
77
import { CSSProperties, RefObject, useCallback, useEffect, useRef, useState } from "react";
88

9+
/**
10+
* @todo Explain why we need this sophisticated iframe size calculation/CSS transform trickery.
11+
*
12+
* The reason is that the Wix website we are using is not truly responsive for iframe
13+
* scenarios. While the usual way to handle this is with CSS media queries, Wix uses a
14+
* User-Agent detection approach.
15+
*
16+
* So, when we embed it in an iframe (where the width is unknown and depends on the
17+
* margin/padding of its container, i.e., resource-iframe.tsx), the iframe's inner
18+
* content is not responsive when the frame is smaller than a certain pixel value.
19+
* e.g. DESKTOP screen + 500px width iframe -> broken
20+
*
21+
* For mobile screens, due to the hacky way Wix implements its layout (using absolute
22+
* pixel positioning like `left: 274px` instead of percentages), embedding it in an
23+
* iframe always results in gaps on the left and right. In other words, the elements
24+
* are not auto-scaled to fit the full iframe width.
25+
* e.g. MOBILE screen + full width iframe -> broken
26+
*/
927
const IFRAME_SIZE = {
1028
/**
1129
* For Wix, mobile UA serves:
@@ -15,9 +33,9 @@ const IFRAME_SIZE = {
1533
* Hence MOBILE_WIDTH = 320.
1634
*/
1735
MOBILE_WIDTH: 320,
18-
DESKTOP_WIDTH: 1440,
36+
DESKTOP_WIDTH: 1338,
1937
/** DEFAULT_WIDTH = DESKTOP_WIDTH */
20-
DEFAULT_WIDTH: 1440,
38+
DEFAULT_WIDTH: 1338,
2139
/** Non-fullscreen view iframe height in /resource page */
2240
HEIGHT: 400,
2341
} as const;
@@ -160,7 +178,7 @@ export function ResourceIframe({
160178
title={title}
161179
allowFullScreen
162180
loading="lazy"
163-
className="border-0"
181+
className="border-0 w-full"
164182
style={{
165183
transform: `scale(${finalScale})`,
166184
transformOrigin: "top left",

src/lib/resources.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export type Resource = {
44
websiteUrl: string;
55
hideTopPx: number;
66
authorLine?: string;
7+
scale?: number;
78
};
89

910
export const resources: Resource[] = [
@@ -20,6 +21,7 @@ export const resources: Resource[] = [
2021
websiteUrl: "https://thespineofthenation.wordpress.com/2025/07/22/the-spine-of-the-nation/",
2122
hideTopPx: 49,
2223
authorLine: "Mr Richard Yan (ALPHA Summer Program 2025)",
24+
scale: 1,
2325
},
2426
];
2527

0 commit comments

Comments
 (0)