Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace last 'export default MDXContent;' #2045

Merged
merged 2 commits into from
Jul 8, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/nextra/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ const __nextraPageOptions = {
(themeConfigImport && 'themeConfig: __nextra_themeConfig')
}
}
${finalResult.replace('export default MDXContent;', '')}
${finalResult.replace(/(export default MDXContent;).*$/, '$1')}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice catch, just one suggestion that we need only replace a last appearance and all code that comes after
image
maybe some solution with String#lastIndexOf and String#slice

could You add also a helpful comment in code why we did it and could you add changeset with patch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review.

I apologize for pushing the wrong regex code.
What I intended was
${finalResult.replace(/export default MDXContent;(.*)$/, '$1')}

I used regex to minimize the changes, but I'll think about using String#lastIndexOf.

could You add also a helpful comment in code why we did it and could you add changeset with patch?

I'll try it later!

if (process.env.NODE_ENV !== 'production') {
__nextraPageOptions.hot = module.hot
__nextraPageOptions.pageOptsChecksum = ${stringifiedChecksum}
Expand Down