|
1 | 1 | const fs = require('fs');
|
2 | 2 | const path = require('path');
|
3 | 3 | const Markdoc = require('@markdoc/markdoc');
|
| 4 | +const {defaultObject} = require('./runtime'); |
4 | 5 |
|
5 | 6 | const DEFAULT_SCHEMA_PATH = './markdoc';
|
6 | 7 |
|
@@ -68,20 +69,24 @@ async function load(source) {
|
68 | 69 |
|
69 | 70 | // Only run validation when during client compilation
|
70 | 71 | if (!nextRuntime) {
|
| 72 | + // This is just to get subcompilation working with Next.js's fast refresh |
71 | 73 | let previousRefreshReg = global.$RefreshReg$;
|
72 | 74 | let previousRefreshSig = global.$RefreshSig$;
|
73 |
| - |
| 75 | + let previousDocument = global.$RefreshSig$; |
| 76 | + let previousElement = global.Element; |
74 | 77 | // https://github.com/pmmmwh/react-refresh-webpack-plugin/issues/176#issuecomment-683150213
|
75 | 78 | global.$RefreshReg$ = noop;
|
76 | 79 | global.$RefreshSig$ = () => noop;
|
| 80 | + global.document = {querySelector: noop}; |
| 81 | + global.Element = class Element {}; |
77 | 82 |
|
78 | 83 | // This imports the config as an in-memory object
|
79 | 84 | const importAtBuildTime = async (resource) => {
|
80 | 85 | try {
|
81 | 86 | const object = await this.importModule(
|
82 | 87 | await resolve(schemaDir, resource)
|
83 | 88 | );
|
84 |
| - return object ? object.default || object : {}; |
| 89 | + return defaultObject(object); |
85 | 90 | } catch (error) {
|
86 | 91 | return undefined;
|
87 | 92 | }
|
@@ -147,6 +152,8 @@ async function load(source) {
|
147 | 152 |
|
148 | 153 | global.$RefreshReg$ = previousRefreshReg;
|
149 | 154 | global.$RefreshSig$ = previousRefreshSig;
|
| 155 | + global.document = previousDocument; |
| 156 | + global.Element = previousElement; |
150 | 157 | }
|
151 | 158 |
|
152 | 159 | const partials = await gatherPartials.call(
|
|
0 commit comments