Skip to content

Commit ece2e1e

Browse files
committed
fix($core): "slotKey" must be defined as props in user's markdown's script tag (close: #975)
1 parent a56c3b4 commit ece2e1e

File tree

7 files changed

+23
-42
lines changed

7 files changed

+23
-42
lines changed

packages/@vuepress/core/lib/app/components/Content.js

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
import Vue from 'vue'
22

33
export default {
4-
functional: true,
54
props: {
65
pageKey: String,
7-
slotKey: String
6+
slotKey: {
7+
type: String,
8+
default: 'default'
9+
}
810
},
9-
render (h, { parent, props, data }) {
10-
const pageKey = props.pageKey || parent.$page.key
11+
render (h) {
12+
const pageKey = this.pageKey || this.$parent.$page.key
1113
if (Vue.$vuepress.isPageExists(pageKey)) {
1214
// In SSR, if a component is not registered with the component option
1315
// vue-server-renderer will not be able to resovle it.
1416
if (!parent.$ssrContext) {
1517
Vue.$vuepress.registerPageAsyncComponent(pageKey)
1618
}
1719

18-
return h(pageKey, {
19-
class: [data.class, data.staticClass],
20-
style: data.style,
21-
props: {
22-
slotKey: props.slotKey || 'default'
23-
}
24-
})
20+
return h(pageKey)
2521
}
2622
return h('')
2723
}

packages/@vuepress/core/lib/app/components/Content.vue

+12-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ export default {
2424
2525
props: {
2626
pageKey: String,
27-
slotKey: String
27+
slotKey: {
28+
type: String,
29+
default: 'default'
30+
}
2831
},
2932
3033
data () {
@@ -72,20 +75,25 @@ export default {
7275
this.noTransition = true
7376
return
7477
}
78+
7579
// Start to load unfetched page component.
7680
this.layout = CONTENT_LOADING_COMPONENT
7781
if (this.$vuepress.isPageExists(pageKey)) {
7882
this.noTransition = false
7983
if (!this.$ssrContext) {
8084
Promise.all([
8185
this.$vuepress.loadPageAsyncComponent(pageKey),
82-
new Promise(resolve => setTimeout(resolve, 300))
86+
new Promise(resolve => setTimeout(resolve, 1000))
8387
]).then(([comp]) => {
8488
this.$vuepress.$emit('AsyncMarkdownAssetLoaded', this.pageKey)
8589
Vue.component(pageKey, comp.default)
8690
this.layout = null
8791
setTimeout(() => {
8892
this.layout = pageKey
93+
setTimeout(() => {
94+
this.$vuepress.$set('contentMounted', true)
95+
this.$vuepress.$emit('contentMounted', this.slotKey)
96+
})
8997
})
9098
})
9199
}
@@ -99,7 +107,8 @@ export default {
99107
.fade-enter-active, .fade-leave-active {
100108
transition: opacity .2s;
101109
}
102-
.fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
110+
111+
.fade-enter, .fade-leave-to {
103112
opacity: 0;
104113
}
105114
</style>

packages/@vuepress/core/lib/app/plugins/VuePress.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ declare class VuePress extends Store {
1414
}
1515

1616
declare module "vue/types/vue" {
17-
interface Vue {
17+
export interface Vue {
1818
$vuepress: VuePress;
1919
}
2020
}

packages/@vuepress/core/lib/app/root-mixins/updateLoadingState.js

-13
This file was deleted.

packages/@vuepress/core/lib/internal-plugins/rootMixins.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ module.exports = (options, context, api) => ({
77
// @internal/root-mixins
88
async clientDynamicModules () {
99
const builtInRootMixins = [
10-
path.resolve(__dirname, '../app/root-mixins/updateMeta.js'),
11-
path.resolve(__dirname, '../app/root-mixins/updateLoadingState.js')
10+
path.resolve(__dirname, '../app/root-mixins/updateMeta.js')
1211
]
1312

1413
const rootMixins = [

packages/@vuepress/markdown-loader/index.js

+1-11
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,8 @@ module.exports = function (src) {
100100

101101
const res = (
102102
`<template>\n` +
103-
`<ContentSlotsDistributor :slot-key="slotKey">${html}</ContentSlotsDistributor>\n` +
103+
`<ContentSlotsDistributor :slot-key="$parent.slotKey">${html}</ContentSlotsDistributor>\n` +
104104
`</template>\n` +
105-
`<script>
106-
export default {
107-
props: ['slot-key'],
108-
mounted() {
109-
this.$nextTick(function () {
110-
this.$vuepress.$emit('AsyncMarkdownContentMounted', this.slotKey)
111-
})
112-
}
113-
}
114-
</script>` +
115105
(hoistedTags || []).join('\n') +
116106
`\n${dataBlockString}\n`
117107
)

packages/@vuepress/plugin-active-header-links/mixin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function getAnchors (sidebarLinks) {
4242

4343
export default {
4444
mounted () {
45-
this.$vuepress.$on('AsyncMarkdownContentMounted', (slotKey) => {
45+
this.$vuepress.$on('contentMounted', (slotKey) => {
4646
if (slotKey === 'default') {
4747
window.addEventListener('scroll', this.onScroll)
4848
}

0 commit comments

Comments
 (0)