Skip to content

fix: wrap Code.astro inline script in IIFE to fix top-level return error#1556

Open
saschabuehrle wants to merge 1 commit into
withstudiocms:mainfrom
saschabuehrle:fix/issue-1555
Open

fix: wrap Code.astro inline script in IIFE to fix top-level return error#1556
saschabuehrle wants to merge 1 commit into
withstudiocms:mainfrom
saschabuehrle:fix/issue-1555

Conversation

@saschabuehrle

@saschabuehrle saschabuehrle commented Jul 6, 2026

Copy link
Copy Markdown

Fixes #1555

The is:inline script in Code.astro uses bare return statements for early exits, but since inline scripts get placed directly in a <script> tag in the HTML output, return outside a function body is a syntax error.

Wrapped the script body in an IIFE so the early returns work as intended.

-- saschabuehrle

Summary by CodeRabbit

  • Bug Fixes
    • Improved code diff highlighting so inserted and deleted lines are consistently marked in code blocks.

@saschabuehrle saschabuehrle requested a review from a team as a code owner July 6, 2026 13:40
@changeset-bot

changeset-bot Bot commented Jul 6, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: d628c03

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 57513f6e-5066-427f-9d06-e10871401d78

📥 Commits

Reviewing files that changed from the base of the PR and between f7646fe and d628c03.

📒 Files selected for processing (1)
  • packages/studiocms/frontend/components/shared/Code.astro

📝 Walkthrough

Walkthrough

The inline script in Code.astro that applies diff highlighting (adding diff, ins, del classes based on data-lines-inserted/data-lines-deleted attributes) is wrapped in an immediately-invoked function expression (IIFE), fixing a compiler error from a top-level return statement.

Changes

Diff Highlighting Script Fix

Layer / File(s) Summary
Wrap diff-highlighting logic in IIFE
packages/studiocms/frontend/components/shared/Code.astro
The inline script's DOM lookup, line-number parsing, and .line element class assignment logic are wrapped in an IIFE instead of running at the top level, resolving an invalid top-level return statement error.

Related Issues: #1555 — "A 'return' statement can only be used within a function body" compile error on the /done setup page, caused by a top-level return inside the inline script.

Suggested Labels: bug, frontend

Suggested Reviewers: (none identified from available information)

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is specific, scoped to Code.astro, and accurately describes the IIFE refactor.
Linked Issues check ✅ Passed The change matches issue #1555 by wrapping the inline script in an IIFE and preserving early exits.
Out of Scope Changes check ✅ Passed The PR appears limited to the reported fix and does not introduce unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@Adammatthiesen Adammatthiesen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for helping with this preemptive change on our project, but it needs a changeset and the existing test updated before we can approve and merge.

(See the failing Github Action workflows for more information)

@Adammatthiesen

Copy link
Copy Markdown
Member

@saschabuehrle are you able to apply the requested changes?

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.

[Bug]: A 'return' statement can only be used within a function body.

2 participants