Skip to content

Commit

Permalink
Fix bug introduced with Next.js 12.3.0 (#16)
Browse files Browse the repository at this point in the history
* disable unknown tag for now

* mock document and Element
  • Loading branch information
mfix-stripe authored Sep 20, 2022
1 parent feb8665 commit b304a92
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/loader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require('fs');
const path = require('path');
const Markdoc = require('@markdoc/markdoc');
const {defaultObject} = require('./runtime');

const DEFAULT_SCHEMA_PATH = './markdoc';

Expand Down Expand Up @@ -68,20 +69,24 @@ async function load(source) {

// Only run validation when during client compilation
if (!nextRuntime) {
// This is just to get subcompilation working with Next.js's fast refresh
let previousRefreshReg = global.$RefreshReg$;
let previousRefreshSig = global.$RefreshSig$;

let previousDocument = global.$RefreshSig$;
let previousElement = global.Element;
// https://github.com/pmmmwh/react-refresh-webpack-plugin/issues/176#issuecomment-683150213
global.$RefreshReg$ = noop;
global.$RefreshSig$ = () => noop;
global.document = {querySelector: noop};
global.Element = class Element {};

// This imports the config as an in-memory object
const importAtBuildTime = async (resource) => {
try {
const object = await this.importModule(
await resolve(schemaDir, resource)
);
return object ? object.default || object : {};
return defaultObject(object);
} catch (error) {
return undefined;
}
Expand Down Expand Up @@ -147,6 +152,8 @@ async function load(source) {

global.$RefreshReg$ = previousRefreshReg;
global.$RefreshSig$ = previousRefreshSig;
global.document = previousDocument;
global.Element = previousElement;
}

const partials = await gatherPartials.call(
Expand Down

0 comments on commit b304a92

Please sign in to comment.