Skip to content

Commit

Permalink
Fix saving issues (#1142)
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot authored Oct 12, 2022
1 parent 94403ea commit 3b1ddd6
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 117 deletions.
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"lz-string": "^1.4.4",
"markdown-to-jsx": "^7.1.7",
"marked": "^4.1.1",
"next": "^12.3.1",
"next": "12.2.2",
"next-transpile-modules": "^9.1.0",
"nprogress": "^0.2.0",
"postcss": "^8.4.17",
Expand Down
8 changes: 6 additions & 2 deletions packages/toolpad-app/jest-environment-jsdom.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { TextDecoder, TextEncoder } from 'util';
import fetch, { Headers, Request, Response } from 'node-fetch';

const JsdomEnvironment = require('jest-environment-jsdom').default;
import JsdomEnvironment from 'jest-environment-jsdom';

export default class CustomJsdomEnvironment extends JsdomEnvironment {
async setup() {
await super.setup();

if (!this.global.TextDecoder) {
// @ts-expect-error The polyfill is not 100% spec-compliant
this.global.TextDecoder = TextDecoder;
} else {
throw new Error(`Unnecessary polyfill "TextDecoder"`);
Expand All @@ -20,9 +20,13 @@ export default class CustomJsdomEnvironment extends JsdomEnvironment {
}

if (!this.global.fetch) {
// @ts-expect-error The polyfill is not 100% spec-compliant
this.global.fetch = fetch;
// @ts-expect-error The polyfill is not 100% spec-compliant
this.global.Headers = Headers;
// @ts-expect-error The polyfill is not 100% spec-compliant
this.global.Request = Request;
// @ts-expect-error The polyfill is not 100% spec-compliant
this.global.Response = Response;
} else {
throw new Error(`Unnecessary polyfill "fetch"`);
Expand Down
12 changes: 11 additions & 1 deletion packages/toolpad-app/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { NextRequest, NextResponse, URLPattern } from 'next/server';
import {
NextRequest,
NextResponse,
// @ts-expect-error
// TODO: As soon as next/server exports this member:
// - remove ` as NextURLPattern` from this line
// - remove the line below with `const URLPattern = ...`
URLPattern as NextURLPattern,
} from 'next/server';
import { checkBasicAuthHeader } from './src/server/basicAuth';

const URLPattern = NextURLPattern || (global as any).URLPattern;

const BASIC_AUTH_WHITELIST = [
// Healthcheck must always be public
new URLPattern({ pathname: '/health-check' }),
Expand Down
2 changes: 1 addition & 1 deletion packages/toolpad-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"lodash-es": "^4.17.21",
"mitt": "^3.0.0",
"monaco-editor": "0.34.0",
"next": "12.3.1",
"next": "12.2.2",
"node-fetch": "^2.6.7",
"node-fetch-har": "^1.0.1",
"path-to-regexp": "^6.2.1",
Expand Down
16 changes: 14 additions & 2 deletions packages/toolpad-app/src/server/getLatestRelease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,23 @@ interface GithubRelease {
url: string;
}

function abortSignalTimeout(ms: number): AbortSignal {
// @ts-expect-error See https://github.com/microsoft/TypeScript/issues/48003
if (AbortSignal.timeout) {
console.warn('Next.js support AbortSignal.timeout, remove this polyfill');
// @ts-expect-error See https://github.com/microsoft/TypeScript/issues/48003
return AbortSignal.timeout(ms);
}

const controller = new AbortController();
setTimeout(() => controller.abort(), ms);
return controller.signal;
}

async function fetchRelease(): Promise<GithubRelease> {
const response = await fetch(LATEST_RELEASE_API_URL, {
// Abort the request after 30 seconds
// @ts-expect-error See https://github.com/microsoft/TypeScript/issues/48003
signal: AbortSignal.timeout(30_000),
signal: abortSignalTimeout(30_000),
});

if (response.ok) {
Expand Down
5 changes: 5 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
"groupName": "core-js",
"matchPackageNames": ["core-js"],
"allowedVersions": "< 2.0.0"
},
{
"groupName": "next",
"matchPackageNames": ["next"],
"allowedVersions": "1.2.2"
}
],
"postUpdateOptions": ["yarnDedupeHighest"],
Expand Down
12 changes: 12 additions & 0 deletions test/integration/large-dom/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as path from 'path';
import { test } from '@playwright/test';
import { ToolpadHome } from '../../models/ToolpadHome';
import { readJsonFile } from '../../utils/fs';

test('large dom', async ({ page }) => {
const dom = await readJsonFile(path.resolve(__dirname, './large.json'));

const homeModel = new ToolpadHome(page);
await homeModel.goto();
await homeModel.createApplication({ dom });
});
43 changes: 43 additions & 0 deletions test/integration/large-dom/large.json

Large diffs are not rendered by default.

Loading

0 comments on commit 3b1ddd6

Please sign in to comment.