Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(Page): handle failed dynamic content loading safely#8006

Merged
alexander-akait merged 5 commits into
webpack:mainfrom
mr-baraiya:fix-content-error
Mar 18, 2026
Merged

fix(Page): handle failed dynamic content loading safely#8006
alexander-akait merged 5 commits into
webpack:mainfrom
mr-baraiya:fix-content-error

Conversation

@mr-baraiya
Copy link
Copy Markdown
Contributor

When content is a Promise and fails to resolve, the previous implementation set a plain string as fallback content. However, the render logic expects structured content.

This change introduces a safe error object and renders a clear fallback message to prevent potential runtime issues.

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 13, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
webpack-js-org Ready Ready Preview, Comment Mar 17, 2026 6:27pm

Request Review

Copy link
Copy Markdown
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Please write cypress test for such things

@mr-baraiya
Copy link
Copy Markdown
Contributor Author

I've added a Cypress E2E test to verify that a fallback error message is rendered when dynamic content fails to load.

@alexander-akait
Copy link
Copy Markdown
Member

Looks like test doesn't work

@mr-baraiya
Copy link
Copy Markdown
Contributor Author

I’ve updated the Cypress test again, but it still seems to fail in CI. Could you please point out the correct scenario we should test for the dynamic content failure case?

@alexander-akait
Copy link
Copy Markdown
Member

alexander-akait commented Mar 14, 2026

@mr-baraiya You should test your code, just reproduce your problem

@mr-baraiya
Copy link
Copy Markdown
Contributor Author

Updated the Cypress test.

Comment thread cypress/e2e/page-content-error.cy.js Outdated
@mr-baraiya
Copy link
Copy Markdown
Contributor Author

@alexander-akait

I've updated the Cypress test based on your feedback and removed the earlier interception logic.
All CI checks are now passing. Could you please take another look when you have time?

@mr-baraiya
Copy link
Copy Markdown
Contributor Author

Just a small follow-up on this PR.

The Cypress test has been updated based on the earlier feedback and the interception logic has been removed. All CI checks are passing now.

Please let me know if any further changes are needed. Thanks!

} else if (content && content.__error) {
contentRender = (
<div className="text-red-600 font-bold">{content.message}</div>
);
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.

Can we add a test case for this

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do you mean adding a unit test for the content.__error branch to verify that the error message is rendered?

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.

Yes

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.

Can we get this route on the real site? I feel like we are adding something what never be happened

Copy link
Copy Markdown
Contributor Author

@mr-baraiya mr-baraiya Mar 17, 2026

Choose a reason for hiding this comment

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

This case can occur if dynamic content (MDX import) fails to resolve at runtime — for example:
broken or missing MDX file
network issues during dynamic import
incorrect path or deployment mismatch

Previously, this resulted in a plain string fallback, which breaks the render logic since it expects structured content. This change ensures the component handles such failures safely and avoids runtime crashes by providing a structured fallback

The unit test verifies that this fallback is rendered correctly when such a failure occurs.

test(Page): add unit test for content.__error rendering and fix test setup
@mr-baraiya
Copy link
Copy Markdown
Contributor Author

I've added a unit test for the content.__error branch to verify that the error message is rendered as requested.
Could you please review?

@alexander-akait alexander-akait merged commit e4f4aa8 into webpack:main Mar 18, 2026
9 checks passed
@mr-baraiya mr-baraiya deleted the fix-content-error branch March 18, 2026 13:45
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.

2 participants