Skip to content

Commit b304a92

Browse files
authored
Fix bug introduced with Next.js 12.3.0 (#16)
* disable unknown tag for now * mock document and Element
1 parent feb8665 commit b304a92

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/loader.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const fs = require('fs');
22
const path = require('path');
33
const Markdoc = require('@markdoc/markdoc');
4+
const {defaultObject} = require('./runtime');
45

56
const DEFAULT_SCHEMA_PATH = './markdoc';
67

@@ -68,20 +69,24 @@ async function load(source) {
6869

6970
// Only run validation when during client compilation
7071
if (!nextRuntime) {
72+
// This is just to get subcompilation working with Next.js's fast refresh
7173
let previousRefreshReg = global.$RefreshReg$;
7274
let previousRefreshSig = global.$RefreshSig$;
73-
75+
let previousDocument = global.$RefreshSig$;
76+
let previousElement = global.Element;
7477
// https://github.com/pmmmwh/react-refresh-webpack-plugin/issues/176#issuecomment-683150213
7578
global.$RefreshReg$ = noop;
7679
global.$RefreshSig$ = () => noop;
80+
global.document = {querySelector: noop};
81+
global.Element = class Element {};
7782

7883
// This imports the config as an in-memory object
7984
const importAtBuildTime = async (resource) => {
8085
try {
8186
const object = await this.importModule(
8287
await resolve(schemaDir, resource)
8388
);
84-
return object ? object.default || object : {};
89+
return defaultObject(object);
8590
} catch (error) {
8691
return undefined;
8792
}
@@ -147,6 +152,8 @@ async function load(source) {
147152

148153
global.$RefreshReg$ = previousRefreshReg;
149154
global.$RefreshSig$ = previousRefreshSig;
155+
global.document = previousDocument;
156+
global.Element = previousElement;
150157
}
151158

152159
const partials = await gatherPartials.call(

0 commit comments

Comments
 (0)