Skip to content

Conversation

AgentHagu
Copy link
Contributor

@AgentHagu AgentHagu commented May 30, 2025

What is the purpose of this pull request?

  • Documentation update
  • Bug fix
  • Feature addition or enhancement
  • Code maintenance
  • DevOps
  • Improve developer experience
  • Others, please explain:

Overview of changes:
Fixes #2715

The code updates MarkBind's existing patch of live-server to account for the number of <svg>s in the HTML file and adjusts the Content-Length header accordingly.

Anything you'd like to highlight/discuss:
Thanks to @gerteck for finding the root cause and a fix for it.

The root cause of the issue was the code injection within the live-server package. It would normally detect <body>, <svg> or <head> and inject the <script> for live-server there. It would also increase the Content-Length by the length of the injected code.

The issue came about because of the use of es.replace(). According to the event-stream npm page, rather than replacing just the first occurrence, it replaces all matching occurrences. This meant that when a file had multiple <svg>s, it would inject code into all of them but only increase the Content-Length once. This lead to the resulting HTML response being cutoff and causing missing content.

Testing instructions:

  1. Run npm run build:backend
  2. Create a panel such as
<panel src="./test.md" />
  1. In the file test.md, include a codeblock, such as:
```
Test
```

You should see this
  1. Add the codeBlockCopyButtons and codeBlockWrapButtons plugins (or replace the codeblock with >2 <svg>s)
  2. Verify that all content is shown as expected after the codeblock (or <svg>s)
    image

Proposed commit message: (wrap lines at 72 characters)
Fix multiple <svg> and missing content issue

live-server injects code into every <svg> occurrence but only
increases the Content-Length value once. This commit fixes this
issue by counting the number of <svg> and increasing the
Content-Length accordingly, ensuring that all content is properly
sent.


Checklist: ☑️

  • Updated the documentation for feature additions and enhancements
  • Added tests for bug fixes or features
  • Linked all related issues
  • No unrelated changes

Reviewer checklist:

Indicate the SEMVER impact of the PR:

  • Major (when you make incompatible API changes)
  • Minor (when you add functionality in a backward compatible manner)
  • Patch (when you make backward compatible bug fixes)

At the end of the review, please label the PR with the appropriate label: r.Major, r.Minor, r.Patch.

Breaking change release note preparation (if applicable):

  • To be included in the release note for any feature that is made obsolete/breaking

Give a brief explanation note about:

  • what was the old feature that was made obsolete
  • any replacement feature (if any), and
  • how the author should modify his website to migrate from the old feature to the replacement feature (if possible).

Copy link

codecov bot commented May 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 52.84%. Comparing base (9c33eb4) to head (c51d973).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #2722    +/-   ##
========================================
  Coverage   52.84%   52.84%            
========================================
  Files         130      130            
  Lines        7162     7162            
  Branches     1503     1572    +69     
========================================
  Hits         3785     3785            
- Misses       3072     3222   +150     
+ Partials      305      155   -150     

☔ 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.

@AgentHagu AgentHagu changed the title Fix issue of multiple <svg>s and missing content Fix multiple <svg> and missing content issue May 30, 2025
@damithc damithc requested a review from Copilot May 30, 2025 13:13
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes an issue with multiple elements triggering redundant code injection, resulting in an incorrect Content-Length header that causes missing content in HTML responses.

  • Adjusts the regex for matching tags to count all occurrences
  • Corrects the Content-Length calculation by multiplying the injection code length by the number of matches

Copy link
Contributor

@gerteck gerteck left a comment

Choose a reason for hiding this comment

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

This PR addresses the cause of HTML content being cut-off when being served by live-server, specifically in the case where there are more than 1 <svg> files.

Some things to perhaps consider beyond the scope of this PR or project:

  • If my understanding is correct, the original package implementation only intended to inject the svg script once, but inadvertently injected multiple duplicate scripts. This fix accounts for this side effect of duplicate injection, but does not inherently resolve the duplicate injection.

    • (Which could have performance impacts in some small edge cases, e.g. 999x <svg> served in a html file)
  • In the event that the original package is updated to resolve this issue, it will have to manually updated through MarkBind's patch in this file, which should be made known to future maintainers that may read this PR.

Overall, this PR successfully resolves the bug through the existing patch of the live-server package. LGTM. Thank you for your help! @AgentHagu

@gerteck gerteck merged commit 1014aad into MarkBind:master Jun 3, 2025
11 checks passed
@github-actions github-actions bot added the r.Patch Version resolver: increment by 0.0.1 label Jun 3, 2025
@damithc
Copy link
Contributor

damithc commented Jun 15, 2025

@AgentHagu @gerteck Thanks for this fix. Shall we do release a minor version including this fix (and any other recent/ready fixes)? I'm still waiting to upgrade to V6 due to this issue.

@gerteck
Copy link
Contributor

gerteck commented Jun 15, 2025

@AgentHagu @gerteck Thanks for this fix. Shall we do release a minor version including this fix (and any other recent/ready fixes)? I'm still waiting to upgrade to V6 due to this issue.

Will follow up on this! I think I will need to get the appropriate permissions on NPM to make a new release

@damithc
Copy link
Contributor

damithc commented Jun 18, 2025

I think I will need to get the appropriate permissions on NPM to make a new release

@lhw-1 @tlylt Can help with this?

@damithc
Copy link
Contributor

damithc commented Jun 19, 2025

Tried v6.0.1. #2715 seems to be fixed now. Thanks everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
r.Patch Version resolver: increment by 0.0.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Part of text goes missing when nested inside panel(s)
3 participants