Skip to content

Commit

Permalink
82ae67e fix(TextEncoderStream): emoji encoding polyfill and add tests…
Browse files Browse the repository at this point in the history
  • Loading branch information
octet-stream committed Jun 8, 2024
1 parent 2aaf9cf commit 75c255e
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 110 deletions.
4 changes: 2 additions & 2 deletions middleware/cloudflare-pages/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {
mergeHeadersCookies,
requestHandler,
_TextEncoderStream_polyfill2
_TextEncoderStream_polyfill
} from "../request-handler/index.mjs";
import { getNotFound } from "@qwik-city-not-found-paths";
import { isStaticPath } from "@qwik-city-static-paths";
Expand All @@ -12,7 +12,7 @@ function createQwikCity(opts) {
try {
new globalThis.TextEncoderStream();
} catch (e) {
globalThis.TextEncoderStream = _TextEncoderStream_polyfill2;
globalThis.TextEncoderStream = _TextEncoderStream_polyfill;
}
const qwikSerializer = {
_deserializeData,
Expand Down
43 changes: 7 additions & 36 deletions middleware/request-handler/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ __export(request_handler_exports, {
RedirectMessage: () => RedirectMessage,
ServerError: () => ServerError,
_TextEncoderStream_polyfill: () => _TextEncoderStream_polyfill,
_TextEncoderStream_polyfill2: () => _TextEncoderStream_polyfill2,
getErrorHtml: () => getErrorHtml,
mergeHeadersCookies: () => mergeHeadersCookies,
requestHandler: () => requestHandler
Expand Down Expand Up @@ -883,7 +882,7 @@ var RequestRouteName = "@routeName";
var RequestEvSharedActionId = "@actionId";
var RequestEvSharedActionFormData = "@actionFormData";
var RequestEvSharedNonce = "@nonce";
function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, manifest, trailingSlash, basePathname, qwikSerializer, resolved2) {
function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, manifest, trailingSlash, basePathname, qwikSerializer, resolved) {
const { request, platform, env } = serverRequestEv;
const sharedMap = /* @__PURE__ */ new Map();
const cookie = new Cookie(request.headers.get("cookie"));
Expand Down Expand Up @@ -1077,7 +1076,7 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, manif
status,
headers,
cookie,
resolved2,
resolved,
requestEv
);
}
Expand Down Expand Up @@ -1466,22 +1465,23 @@ var _TextEncoderStream_polyfill = class {
transform: (chunk, controller) => {
chunk = String(chunk);
let finalChunk = "";
for (const item of chunk) {
for (let i = 0; i < chunk.length; i++) {
const item = chunk[i];
const codeUnit = item.charCodeAt(0);
if (this.#pendingHighSurrogate !== null) {
const highSurrogate = this.#pendingHighSurrogate;
this.#pendingHighSurrogate = null;
if (codeUnit >= 56320 && codeUnit <= 57343) {
if (56320 <= codeUnit && codeUnit <= 57343) {
finalChunk += highSurrogate + item;
continue;
}
finalChunk += "\uFFFD";
}
if (codeUnit >= 55296 && codeUnit <= 56319) {
if (55296 <= codeUnit && codeUnit <= 56319) {
this.#pendingHighSurrogate = item;
continue;
}
if (codeUnit >= 56320 && codeUnit <= 57343) {
if (56320 <= codeUnit && codeUnit <= 57343) {
finalChunk += "\uFFFD";
continue;
}
Expand Down Expand Up @@ -1510,41 +1510,12 @@ var _TextEncoderStream_polyfill = class {
return "TextEncoderStream";
}
};
var resolved = Promise.resolve();
var _TextEncoderStream_polyfill2 = class {
constructor() {
this._writer = null;
this.readable = {
pipeTo: (writableStream) => {
this._writer = writableStream.getWriter();
}
};
this.writable = {
getWriter: () => {
if (!this._writer) {
throw new Error("No writable stream");
}
const encoder2 = new TextEncoder();
return {
write: async (chunk) => {
if (chunk != null) {
await this._writer.write(encoder2.encode(chunk));
}
},
close: () => this._writer.close(),
ready: resolved
};
}
};
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
AbortMessage,
RedirectMessage,
ServerError,
_TextEncoderStream_polyfill,
_TextEncoderStream_polyfill2,
getErrorHtml,
mergeHeadersCookies,
requestHandler
Expand Down
8 changes: 0 additions & 8 deletions middleware/request-handler/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -675,12 +675,4 @@ export declare class _TextEncoderStream_polyfill {
get [Symbol.toStringTag](): string;
}

/** @internal */
export declare class _TextEncoderStream_polyfill2 {
_writer: any;
readable: any;
writable: any;
constructor();
}

export { }
42 changes: 7 additions & 35 deletions middleware/request-handler/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ var RequestRouteName = "@routeName";
var RequestEvSharedActionId = "@actionId";
var RequestEvSharedActionFormData = "@actionFormData";
var RequestEvSharedNonce = "@nonce";
function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, manifest, trailingSlash, basePathname, qwikSerializer, resolved2) {
function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, manifest, trailingSlash, basePathname, qwikSerializer, resolved) {
const { request, platform, env } = serverRequestEv;
const sharedMap = /* @__PURE__ */ new Map();
const cookie = new Cookie(request.headers.get("cookie"));
Expand Down Expand Up @@ -1034,7 +1034,7 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, manif
status,
headers,
cookie,
resolved2,
resolved,
requestEv
);
}
Expand Down Expand Up @@ -1423,22 +1423,23 @@ var _TextEncoderStream_polyfill = class {
transform: (chunk, controller) => {
chunk = String(chunk);
let finalChunk = "";
for (const item of chunk) {
for (let i = 0; i < chunk.length; i++) {
const item = chunk[i];
const codeUnit = item.charCodeAt(0);
if (this.#pendingHighSurrogate !== null) {
const highSurrogate = this.#pendingHighSurrogate;
this.#pendingHighSurrogate = null;
if (codeUnit >= 56320 && codeUnit <= 57343) {
if (56320 <= codeUnit && codeUnit <= 57343) {
finalChunk += highSurrogate + item;
continue;
}
finalChunk += "\uFFFD";
}
if (codeUnit >= 55296 && codeUnit <= 56319) {
if (55296 <= codeUnit && codeUnit <= 56319) {
this.#pendingHighSurrogate = item;
continue;
}
if (codeUnit >= 56320 && codeUnit <= 57343) {
if (56320 <= codeUnit && codeUnit <= 57343) {
finalChunk += "\uFFFD";
continue;
}
Expand Down Expand Up @@ -1467,40 +1468,11 @@ var _TextEncoderStream_polyfill = class {
return "TextEncoderStream";
}
};
var resolved = Promise.resolve();
var _TextEncoderStream_polyfill2 = class {
constructor() {
this._writer = null;
this.readable = {
pipeTo: (writableStream) => {
this._writer = writableStream.getWriter();
}
};
this.writable = {
getWriter: () => {
if (!this._writer) {
throw new Error("No writable stream");
}
const encoder2 = new TextEncoder();
return {
write: async (chunk) => {
if (chunk != null) {
await this._writer.write(encoder2.encode(chunk));
}
},
close: () => this._writer.close(),
ready: resolved
};
}
};
}
};
export {
AbortMessage,
RedirectMessage,
ServerError,
_TextEncoderStream_polyfill,
_TextEncoderStream_polyfill2,
getErrorHtml,
mergeHeadersCookies,
requestHandler
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@builder.io/qwik-city",
"description": "The meta-framework for Qwik.",
"version": "1.5.5-dev20240607002637",
"version": "1.5.5-dev20240608004335",
"bugs": "https://github.com/QwikDev/qwik/issues",
"dependencies": {
"@mdx-js/mdx": "^3.0.1",
Expand Down
23 changes: 9 additions & 14 deletions vite/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -24375,13 +24375,13 @@ async function updateBuildContext(ctx) {
ctx.serverPlugins = serverPlugins;
return walkRoutes(ctx.opts.routesDir);
}).then((sourceFiles) => {
const resolved2 = resolveSourceFiles(ctx.opts, sourceFiles);
rewriteRoutes(ctx, resolved2);
ctx.layouts = resolved2.layouts;
ctx.routes = resolved2.routes;
ctx.entries = resolved2.entries;
ctx.serviceWorkers = resolved2.serviceWorkers;
ctx.menus = resolved2.menus;
const resolved = resolveSourceFiles(ctx.opts, sourceFiles);
rewriteRoutes(ctx, resolved);
ctx.layouts = resolved.layouts;
ctx.routes = resolved.routes;
ctx.entries = resolved.entries;
ctx.serviceWorkers = resolved.serviceWorkers;
ctx.menus = resolved.menus;
resolve4();
}, reject).finally(() => {
ctx.activeBuild = null;
Expand Down Expand Up @@ -25267,7 +25267,7 @@ var RequestRouteName = "@routeName";
var RequestEvSharedActionId = "@actionId";
var RequestEvSharedActionFormData = "@actionFormData";
var RequestEvSharedNonce = "@nonce";
function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, manifest, trailingSlash, basePathname, qwikSerializer, resolved2) {
function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, manifest, trailingSlash, basePathname, qwikSerializer, resolved) {
const { request, platform, env: env2 } = serverRequestEv;
const sharedMap = /* @__PURE__ */ new Map();
const cookie = new Cookie(request.headers.get("cookie"));
Expand Down Expand Up @@ -25461,7 +25461,7 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, manif
status,
headers,
cookie,
resolved2,
resolved,
requestEv
);
}
Expand Down Expand Up @@ -26572,11 +26572,6 @@ navigator.serviceWorker?.getRegistrations().then((regs) => {
// packages/qwik-city/adapters/shared/vite/post-build.ts
var import_node_fs7 = __toESM(require("node:fs"), 1);
var import_node_path9 = require("node:path");

// packages/qwik-city/middleware/request-handler/polyfill.ts
var resolved = Promise.resolve();

// packages/qwik-city/adapters/shared/vite/post-build.ts
async function postBuild(clientOutDir, basePathname, userStaticPaths, format, cleanStatic) {
const ignorePathnames = /* @__PURE__ */ new Set([basePathname + "build/", basePathname + "assets/"]);
const staticPaths = new Set(userStaticPaths.map(normalizeTrailingSlash));
Expand Down
23 changes: 9 additions & 14 deletions vite/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24365,13 +24365,13 @@ async function updateBuildContext(ctx) {
ctx.serverPlugins = serverPlugins;
return walkRoutes(ctx.opts.routesDir);
}).then((sourceFiles) => {
const resolved2 = resolveSourceFiles(ctx.opts, sourceFiles);
rewriteRoutes(ctx, resolved2);
ctx.layouts = resolved2.layouts;
ctx.routes = resolved2.routes;
ctx.entries = resolved2.entries;
ctx.serviceWorkers = resolved2.serviceWorkers;
ctx.menus = resolved2.menus;
const resolved = resolveSourceFiles(ctx.opts, sourceFiles);
rewriteRoutes(ctx, resolved);
ctx.layouts = resolved.layouts;
ctx.routes = resolved.routes;
ctx.entries = resolved.entries;
ctx.serviceWorkers = resolved.serviceWorkers;
ctx.menus = resolved.menus;
resolve4();
}, reject).finally(() => {
ctx.activeBuild = null;
Expand Down Expand Up @@ -25257,7 +25257,7 @@ var RequestRouteName = "@routeName";
var RequestEvSharedActionId = "@actionId";
var RequestEvSharedActionFormData = "@actionFormData";
var RequestEvSharedNonce = "@nonce";
function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, manifest, trailingSlash, basePathname, qwikSerializer, resolved2) {
function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, manifest, trailingSlash, basePathname, qwikSerializer, resolved) {
const { request, platform, env: env2 } = serverRequestEv;
const sharedMap = /* @__PURE__ */ new Map();
const cookie = new Cookie(request.headers.get("cookie"));
Expand Down Expand Up @@ -25451,7 +25451,7 @@ function createRequestEvent(serverRequestEv, loadedRoute, requestHandlers, manif
status,
headers,
cookie,
resolved2,
resolved,
requestEv
);
}
Expand Down Expand Up @@ -26567,11 +26567,6 @@ navigator.serviceWorker?.getRegistrations().then((regs) => {
// packages/qwik-city/adapters/shared/vite/post-build.ts
import fs6 from "node:fs";
import { join as join5 } from "node:path";

// packages/qwik-city/middleware/request-handler/polyfill.ts
var resolved = Promise.resolve();

// packages/qwik-city/adapters/shared/vite/post-build.ts
async function postBuild(clientOutDir, basePathname, userStaticPaths, format, cleanStatic) {
const ignorePathnames = /* @__PURE__ */ new Set([basePathname + "build/", basePathname + "assets/"]);
const staticPaths = new Set(userStaticPaths.map(normalizeTrailingSlash));
Expand Down

0 comments on commit 75c255e

Please sign in to comment.