Skip to content

fix(escapeHtmlComment): Avoid throwing errors due to src not being a … #12459

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lazytong-tech
Copy link

When building my project, Vue threw the error src. replace is not a function. After adding toString() to the function escapeHtmlComment, this error did not occur again

@skirtles-code
Copy link
Contributor

Are you able to provide a reproduction of the problem?

I don't think this can be merged until we understand the underlying reason why a non-string was passed to this function.

It reminds me of #8870, which turned out to be caused by UnoCSS incorrectly rewriting Vue code.

@lazytong-tech
Copy link
Author

When I use the nuxt3 framework and webpack5 as a builder, using unplugin-auto import/webpack and unplugin-vue components/webpack will result in a TypeError: src. replace is not a function error during server-side rendering.
Here is the error message:

$ node .output/server/index.mjs
Listening on http://[::]:3000
[nitro] [unhandledRejection] TypeError: src.replace is not a function
    at Object.escapeHtmlComment (/workspace/house/.output/server/node_modules/@vue/shared/dist/shared.cjs.prod.js:424:29)
    at renderVNode (/workspace/house/.output/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js:484:34)
    at renderComponentSubTree (/workspace/house/.output/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js:459:7)
    at renderComponentVNode (/workspace/house/.output/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js:394:12)
    at renderVNode (/workspace/house/.output/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js:507:14)
    at renderVNodeChildren (/workspace/house/.output/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js:523:5)
    at renderElementVNode (/workspace/house/.output/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js:567:9)
    at renderVNode (/workspace/house/.output/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js:505:9)
    at renderComponentSubTree (/workspace/house/.output/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js:459:7)
    at renderComponentVNode (/workspace/house/.output/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js:394:12)

After changing

function escapeHtmlComment(src) {
  return src.replace(commentStripRE, "");
}

in @vue/shared dist/shared.cjs.prod.js to

function escapeHtmlComment(src) {
  return src.toString().replace(commentStripRE, "");
}

, the error no longer occurs.
Running environment:

------------------------------
- Operating System: Linux
- Node Version:     v18.20.5
- Nuxt Version:     3.14.159
- CLI Version:      3.14.0
- Nitro Version:    2.10.4
- Package Manager:  [email protected]
- Builder:          -
- User Config:      -
- Runtime Modules:  -
- Build Modules:    -
------------------------------

@edison1105
Copy link
Member

Thanks for the PR. This might fix your problem, but we need more context to analyze the root cause. Please provide a runnable minimal reproduction so that we can investigate the issue.

@edison1105 edison1105 added the need more info Further information is requested label Nov 27, 2024
@lazytong-tech
Copy link
Author

I created a demo at https://cloudstudio.net/a/23155491845591040

@edison1105
Copy link
Member

@lazytong-tech
Thank you for providing the reproduction, it indeed replicates the issue you described. However, the code cannot be downloaded, and I would like to debug it locally to see what the input parameters are.

@lazytong-tech
Copy link
Author

you can download it at https://f002.backblazeb2.com/file/lazytong/demo.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need more info Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants