Skip to content

feat(website): SVG optimization bypass and page block observability#1514

Open
vibegui wants to merge 1 commit intomainfrom
feat/e2e-observability
Open

feat(website): SVG optimization bypass and page block observability#1514
vibegui wants to merge 1 commit intomainfrom
feat/e2e-observability

Conversation

@vibegui
Copy link
Contributor

@vibegui vibegui commented Jan 18, 2026

  • Skip raster optimization for SVG images (vector graphics)
  • Add matchedPageBlock to state for x-deco-page header support

Summary by CodeRabbit

  • Improvements
    • SVG files are now delivered as native images without optimization processing.
    • Enhanced component tracking for page observability.

✏️ Tip: You can customize this high-level summary in your review settings.

- Skip raster optimization for SVG images (vector graphics)
- Add matchedPageBlock to state for x-deco-page header support
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 18, 2026

📝 Walkthrough

Walkthrough

PR adds SVG-specific image handling that bypasses optimization when source ends with .svg, and introduces observability state tracking in the Fresh handler to expose matched page block names for monitoring purposes.

Changes

Cohort / File(s) Summary
Image component SVG handling
website/components/Image.tsx
Introduces isSvg helper and early-return branch for SVG sources (ending with .svg), bypassing raster optimization and srcSet generation to render plain img elements
Fresh handler observability
website/handlers/fresh.ts
Adds state assignment to expose matched page block name (ctx.state.matchedPageBlock) with component name normalized (site/ prefix and .tsx suffix removed) for observability/headers on non-JSON render paths

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • PR #1414: Modifies Image.tsx to add preload/early-hint props and server-side emission, addressing complementary image component runtime behavior.
  • PR #1452: Modifies Image.tsx image optimization path construction (getOptimizedMediaUrl/asset URLs), directly related to the optimization flow being bypassed for SVGs.

Suggested reviewers

  • guitavano

Poem

🐰 A rabbit hops through SVG scenes,
No optimization needed here, if you know what I mean!
Fresh handlers now observe with glee,
Which block matched the page for all to see! 🎨✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive The description is minimal but covers the core changes. However, it lacks required template sections like issue link, loom video, and demonstration link. Add issue link, loom video, and demonstration link sections from the template to provide complete context for reviewers.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main changes: SVG optimization bypass and page block observability enhancements.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Contributor

Tagging Options

Should a new tag be published when this PR is merged?

  • 👍 for Patch 0.133.25 update
  • 🎉 for Minor 0.134.0 update
  • 🚀 for Major 1.0.0 update

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@website/components/Image.tsx`:
- Around line 258-270: The SVG branch in the Image component short-circuits
before handling the preload prop, so when isSvg(props.src) is true any
preload={true} is ignored; update the SVG handling in Image.tsx to run the same
preload/link-registration logic as non‑SVG images (i.e., check props.preload and
emit the Head preload link or call the existing preload helper) before returning
the <img> for SVGs, or remove the early return and render the SVG path after
executing the preload logic so props.preload is honored while keeping
data-fresh-disable-lock, loading, ref and src usage unchanged.

In `@website/handlers/fresh.ts`:
- Around line 235-242: The CI fails deno fmt --check due to quoting and trailing
whitespace in the block that sets matched page block; update the string literals
to use double quotes and remove the trailing whitespace: in the
isFreshCtx<DecoState>(ctx) branch where you set (ctx.state as
any).matchedPageBlock from page.metadata.component, change the regex string
delimiters from single to double quotes (e.g., "^site/" and "\\.tsx$") and
ensure there is no trailing whitespace or blank characters after the closing
brace so the file passes deno fmt.
🧹 Nitpick comments (1)
website/components/Image.tsx (1)

253-254: Consider handling query strings in SVG detection.

The current implementation won't detect SVG files with query parameters (e.g., image.svg?v=1 or image.svg?token=abc). This could cause SVGs with cache-busting or CDN parameters to still go through raster optimization.

🔧 Suggested fix
-const isSvg = (src: string) => src?.toLowerCase().endsWith(".svg");
+const isSvg = (src: string) => {
+  if (!src) return false;
+  const pathWithoutQuery = src.split('?')[0];
+  return pathWithoutQuery.toLowerCase().endsWith('.svg');
+};

Comment on lines +258 to +270
// SVGs are vector graphics and don't need raster optimization
if (isSvg(props.src)) {
return (
<img
{...props}
data-fresh-disable-lock
preload={undefined}
src={props.src}
loading={loading}
ref={ref}
/>
);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

SVG path ignores the preload prop.

When preload={true} is passed for an SVG image, the preload <Head> link is not rendered since the early return bypasses that logic. This could regress LCP for preloaded SVG hero images.

🔧 Suggested fix to support preload for SVG
   // SVGs are vector graphics and don't need raster optimization
   if (isSvg(props.src)) {
     return (
-      <img
-        {...props}
-        data-fresh-disable-lock
-        preload={undefined}
-        src={props.src}
-        loading={loading}
-        ref={ref}
-      />
+      <>
+        {preload && (
+          <Head>
+            <link as="image" rel="preload" href={props.src} />
+          </Head>
+        )}
+        <img
+          {...props}
+          data-fresh-disable-lock
+          preload={undefined}
+          src={props.src}
+          loading={loading}
+          ref={ref}
+        />
+      </>
     );
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// SVGs are vector graphics and don't need raster optimization
if (isSvg(props.src)) {
return (
<img
{...props}
data-fresh-disable-lock
preload={undefined}
src={props.src}
loading={loading}
ref={ref}
/>
);
}
// SVGs are vector graphics and don't need raster optimization
if (isSvg(props.src)) {
return (
<>
{preload && (
<Head>
<link as="image" rel="preload" href={props.src} />
</Head>
)}
<img
{...props}
data-fresh-disable-lock
preload={undefined}
src={props.src}
loading={loading}
ref={ref}
/>
</>
);
}
🤖 Prompt for AI Agents
In `@website/components/Image.tsx` around lines 258 - 270, The SVG branch in the
Image component short-circuits before handling the preload prop, so when
isSvg(props.src) is true any preload={true} is ignored; update the SVG handling
in Image.tsx to run the same preload/link-registration logic as non‑SVG images
(i.e., check props.preload and emit the Head preload link or call the existing
preload helper) before returning the <img> for SVGs, or remove the early return
and render the SVG path after executing the preload logic so props.preload is
honored while keeping data-fresh-disable-lock, loading, ref and src usage
unchanged.

Comment on lines +235 to +242
// Set matched page block name for observability headers
if (isFreshCtx<DecoState>(ctx) && page?.metadata?.component) {
// deno-lint-ignore no-explicit-any
(ctx.state as any).matchedPageBlock = page.metadata.component
.replace(/^site\//, '')
.replace(/\.tsx$/, '');
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix formatting to resolve pipeline failure.

The CI is failing due to deno fmt --check. The issues are:

  1. Single quotes should be double quotes (Deno default)
  2. Trailing whitespace on line 242
🔧 Proposed fix
       // Set matched page block name for observability headers
       if (isFreshCtx<DecoState>(ctx) && page?.metadata?.component) {
         // deno-lint-ignore no-explicit-any
         (ctx.state as any).matchedPageBlock = page.metadata.component
-          .replace(/^site\//, '')
-          .replace(/\.tsx$/, '');
+          .replace(/^site\//, "")
+          .replace(/\.tsx$/, "");
       }
-      
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Set matched page block name for observability headers
if (isFreshCtx<DecoState>(ctx) && page?.metadata?.component) {
// deno-lint-ignore no-explicit-any
(ctx.state as any).matchedPageBlock = page.metadata.component
.replace(/^site\//, '')
.replace(/\.tsx$/, '');
}
// Set matched page block name for observability headers
if (isFreshCtx<DecoState>(ctx) && page?.metadata?.component) {
// deno-lint-ignore no-explicit-any
(ctx.state as any).matchedPageBlock = page.metadata.component
.replace(/^site\//, "")
.replace(/\.tsx$/, "");
}
🧰 Tools
🪛 GitHub Actions: ci

[error] 239-242: deno fmt --check reported: Found 1 not formatted file in 2083 files.

🤖 Prompt for AI Agents
In `@website/handlers/fresh.ts` around lines 235 - 242, The CI fails deno fmt
--check due to quoting and trailing whitespace in the block that sets matched
page block; update the string literals to use double quotes and remove the
trailing whitespace: in the isFreshCtx<DecoState>(ctx) branch where you set
(ctx.state as any).matchedPageBlock from page.metadata.component, change the
regex string delimiters from single to double quotes (e.g., "^site/" and
"\\.tsx$") and ensure there is no trailing whitespace or blank characters after
the closing brace so the file passes deno fmt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant