Skip to content

fix(nextjs): Create root layout for example page if it doesn't exist - #863

Merged
Lms24 merged 3 commits into
masterfrom
lms/fix-nextjs-no-root-layout
Mar 18, 2025
Merged

Lms24 merged 3 commits into
masterfrom
lms/fix-nextjs-no-root-layout

Conversation

@Lms24

@Lms24 Lms24 commented Mar 18, 2025 •

Copy link
Copy Markdown
Member

This PR adds a check for a NextJS root layout file. Some NextJS apps don't have a root layout though, for instance if they only serve API routes. If users still would like to create an example page via the wizard, we also need to add a root layout so that the page can be rendered.

I noticed that newer versions actually create a root layout file automatically in dev mode when first serving the page but this doesn't apply to older NextJS versions. So it's better to handle this explicitly in the wizard. The file we inject is almost identical to the auto-generated one, just with some Sentry-specific text.

This is tested by removing the root layout in our NextJS 14 E2E test app and assuring that it's re-added by our wizard in the tests.

closes #607

@Lms24 Lms24 self-assigned this Mar 18, 2025
@codecov

codecov Bot commented Mar 18, 2025 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 51.55%. Comparing base (6db9e46) to head (78b143f).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #863      +/-   ##
==========================================
+ Coverage   51.50%   51.55%   +0.05%     
==========================================
  Files          53       53              
  Lines        3633     3637       +4     
  Branches      854      857       +3     
==========================================
+ Hits         1871     1875       +4     
  Misses       1632     1632              
  Partials      130      130              
Flag Coverage Δ
e2e-tests 80.85% <ø> (ø)
unit-tests 50.37% <100.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Lms24
Lms24 marked this pull request as ready for review March 18, 2025 14:25
@Lms24
Lms24 requested a review from lforst March 18, 2025 14:26

@lforst lforst left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice! Ty!

@Lms24
Lms24 merged commit 2c74ab1 into master Mar 18, 2025
@Lms24
Lms24 deleted the lms/fix-nextjs-no-root-layout branch March 18, 2025 14:56
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.

[Next.js] Check for existence of root layout before creating test page

2 participants