Skip to content

Commit d6fbc38

Browse files
authored
Fix memory leak in SSR docs (#3386)
* chore: add serve node module to docs * chore: fix generate build command * chore: fix ts build * chore: fix ts build issues and sync all deps * chore: fix i18n build error * fix(docs): markdownit build error * fix: types build and update ts to ^5.0 * raw new markdown * fix(docs): memory leaks in ssr * fix(build): typo * fix(docs): show old props with vue-component-meta * raw markdown plugins * fix(docs): external links * fix(docs): update node to 18 * docs(chore): remove markdown-it * fix(deps): remove hardcoded deps * chore(deps): update ts to 5 * chore(deps): update eslint to ^7
1 parent 92eb61c commit d6fbc38

File tree

67 files changed

+4300
-5587
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+4300
-5587
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v16.16.0
1+
v18.14.0

package.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"repository": "https://github.com/epicmaxco/vuestic-ui",
66
"devDependencies": {
77
"lerna": "^3.20.2",
8+
"syncpack": "^9.8.6",
89
"yorkie": "^2.0.0"
910
},
1011
"private": true,
@@ -17,6 +18,7 @@
1718
"build:book": "yarn workspace vuestic-ui build:book",
1819
"build:types": "yarn workspace vuestic-ui build:types",
1920
"test:unit": "yarn workspace vuestic-ui test:unit",
21+
"test:bundlers": "yarn workspace bundler-test test",
2022
"lint:style": "yarn workspace vuestic-ui lint:style",
2123
"serve:docs": "yarn workspace docs serve",
2224
"build:docs": "yarn workspace docs build",
@@ -39,12 +41,5 @@
3941
},
4042
"gitHooks": {
4143
"pre-commit": "lerna run --concurrency 1 --stream precommit --since HEAD"
42-
},
43-
"resolutions": {
44-
"nuxt": "3.1.1",
45-
"vue": "3.2.37",
46-
"vite": "^4",
47-
"vue-router": "4.1.6",
48-
"@nuxt/schema": "3.0.0"
4944
}
5045
}

packages/deploy/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
"release": "tsx release-script/release-script.ts"
77
},
88
"devDependencies": {
9-
"tsx": "^3.5.0",
9+
"tsx": "^3.12.1",
1010
"inquirer": "^9.0.0",
11-
"typescript": "^4.3.2",
12-
"chalk": "^5.0.1"
11+
"typescript": "^5",
12+
"chalk": "^5.2.0"
1313
},
1414
"exports": {
1515
"./execute": "./execute/index.ts"

packages/docs/i18n.config.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/docs/modules/markdown/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@ export default defineNuxtModule({
66
mame: 'vuestic:markdown',
77
},
88

9-
setup(_, nuxt) {
10-
nuxt.options.plugins.push(resolve(__dirname, 'runtime/plugin.ts'))
11-
12-
9+
setup() {
1310
addImports({
14-
name: 'useMarkdownIt',
15-
as: 'useMarkdownIt',
16-
from: resolve(__dirname, './runtime/useMarkdownIt'),
11+
name: 'useMarkdown',
12+
as: 'useMarkdown',
13+
from: resolve(__dirname, './runtime/useMarkdown'),
1714
})
1815
}
1916
})

packages/docs/modules/markdown/runtime/plugin.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { it, describe, expect } from 'vitest';
2+
import { marked } from 'marked';
3+
import { fixTargetLinks } from './external-links';
4+
5+
describe('externalLinkMarkedPlugin', () => {
6+
it('targetBlankPlugin: adds target="_blank" to links', () => {
7+
const markdown = `[vue-press](https://vuepress.vuejs.org/)[[target=_blank]]`;
8+
const html = fixTargetLinks(marked(markdown));
9+
10+
expect(/target="_blank"/.test(html)).toBeTruthy();
11+
});
12+
})
13+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const addAttrToLink = (str: string, attr: string) => {
2+
const [start, end] = str.split('<a')
3+
return start + '<a ' + attr + end
4+
}
5+
6+
export const fixTargetLinks = (textToRender: string) => {
7+
const targetRegex = /\[\[(.*?)\]\]/g; // Search for the [[target="_blank"]] in the markdown.
8+
const linkRegexPattern = /<a[^>]*>.*<\/a>\[\[(.*)\]\]/g; // Searching for all <a href=""> tags
9+
10+
let matchedTarget;
11+
12+
while ((matchedTarget = linkRegexPattern.exec(textToRender)) !== null) {
13+
let target = matchedTarget[1].trim().replaceAll('&quot;', '"')
14+
if (target === 'target=_blank') {
15+
target = 'target="_blank"';
16+
}
17+
const [link] = matchedTarget
18+
19+
textToRender = addAttrToLink(textToRender
20+
.replace(link, link.replace(targetRegex, '')), target)
21+
}
22+
23+
return textToRender;
24+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Renderer, Parser } from 'marked'
2+
import { Ref } from 'vue'
3+
export const externalLinkStartWith = ['http://', 'https://']
4+
5+
export function localizedLinkMarkedPlugin(locale: Ref<string>) {
6+
const renderer = new Renderer();
7+
const originalRenderer = renderer.link;
8+
9+
renderer.link = function (href, title, text) {
10+
const isExternalLink = externalLinkStartWith.some((item) => href?.startsWith(item))
11+
12+
if (isExternalLink) {
13+
return originalRenderer.call(renderer, href, title, text);
14+
}
15+
16+
const normalizedHref = href?.startsWith('/')
17+
? href.substring(1)
18+
: href
19+
20+
const localePrefix = `${locale.value}/`
21+
22+
if (normalizedHref?.startsWith(localePrefix)) {
23+
return originalRenderer.call(renderer, href, title, text);
24+
}
25+
26+
return originalRenderer.call(renderer, '/' + localePrefix + href, title, text);
27+
}
28+
29+
return { renderer };
30+
}

0 commit comments

Comments
 (0)