Skip to content
This repository was archived by the owner on Jul 20, 2022. It is now read-only.

Add filter for malformed path and mappings.wasm #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/client/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ const StacktraceList = () => {
if (loading) return null;

return (
<ul className="h-screen max-h-screen overflow-y-scroll">
<ul className="h-screen max-h-screen">
{stacktrace.map((line, index) => {
return (
<StackTraceLine key={index} index={index}>
Expand Down
50 changes: 45 additions & 5 deletions src/server/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,30 @@ export const action: ActionFunction = async ({ request }) => {
const url = new URL(request.url);
const root = process.cwd();

const bundledFile = url.searchParams.get("file");
let bundledFile = url.searchParams.get("file");

// The bundledFile path i get here is wrong on some files (because it is composed by 2 file urls)
// and the first is the evil one, ex: process.cwd() + 'build\\route:'
// console.log(bundledFile) yelds:
// C:\Users\daviz\remix-jokes\build\route:C:\daviz\remix-jokes\app\routes\index.tsx
// The stacktrace seems malformed (first line in this example):
/**
*
* Error: stfghdhg
at Index (C:\Users\Win 10\Documents\coding\playground\remix\remix-jokes\build\route:C:\Users\Win 10\Documents\coding\playground\remix\remix-jokes\app\routes\index.tsx:22:9)
at processChild (C:\Users\Win 10\Documents\coding\playground\remix\remix-jokes\node_modules\react-dom\cjs\react-dom-server.node.development.js:3353:14)
at resolve (C:\Users\Win 10\Documents\coding\playground\remix\remix-jokes\node_modules\react-dom\cjs\react-dom-server.node.development.js:3270:5)
at ReactDOMServerRenderer.render (C:\Users\Win 10\Documents\coding\playground\remix\remix-jokes\node_modules\react-dom\cjs\react-dom-server.node.development.js:3753:22)
at ReactDOMServerRenderer.read (C:\Users\Win 10\Documents\coding\playground\remix\remix-jokes\node_modules\react-dom\cjs\react-dom-server.node.development.js:3690:29)
at renderToString (C:\Users\Win 10\Documents\coding\playground\remix\remix-jokes\node_modules\react-dom\cjs\react-dom-server.node.development.js:4298:27)
at handleRequest (C:\Users\Win 10\Documents\coding\playground\remix\remix-jokes\app\entry.server.tsx:11:18)
at renderDocumentRequest (C:\Users\Win 10\Documents\coding\playground\remix\remix-jokes\node_modules\@remix-run\server-runtime\server.js:404:18)
at requestHandler (C:\Users\Win 10\Documents\coding\playground\remix\remix-jokes\node_modules\@remix-run\server-runtime\server.js:55:20)
at C:\Users\Win 10\Documents\coding\playground\remix\remix-jokes\node_modules\@remix-run\express\server.js:43:22
*/
if (bundledFile) {
bundledFile = bundledFile.replace(`${process.cwd()}\\build\\route:`, "");
}
const line = url.searchParams.get("line");
const column = url.searchParams.get("column");

Expand All @@ -85,11 +108,26 @@ export const action: ActionFunction = async ({ request }) => {
});
}

const consumer = await new SourceMapConsumer(rawSourceMap);
const sm : any = SourceMapConsumer;

/*
/* Without this i have error asking to configure 'source-map' like on the Web:
/* Error: You must provide the URL of lib/mappings.wasm by calling SourceMapConsumer.initialize({ 'lib/mappings.wasm': ... }) before using SourceMapConsumer
at readWasm (C:\Users\daviz\remix\node_modules\source-map\lib\read-wasm.js:8:13)
at wasm (C:\Users\daviz\remix-jokes\node_modules\source-map\lib\wasm.js:25:16)
at C:\Users\daviz\remix-jokes\node_modules\source-map\lib\source-map-consumer.js:264:14
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at action (C:\Users\daviz\remix-jokes\app\lib\remix-crash\server\endpoints.server.ts:98:20)
at Object.callRouteAction (C:\Users\daviz\remix-jokes\node_modules\@remix-run\server-runtime\data.js:36:14)
at handleResourceRequest (C:\Users\daviz\remix-jokes\node_modules\@remix-run\server-runtime\server.js:451:14)
at requestHandler (C:\Users\daviz\remix-jokes\node_modules\@remix-run\server-runtime\server.js:66:20)
at C:\Users\daviz\remix-jokes\node_modules\@remix-run\express\server.js:43:22
*/
sm.initialize({
"lib/mappings.wasm": "https://unpkg.com/[email protected]/lib/mappings.wasm"
});

if (!line || !column) {
throw new Error("Failed to load source map");
}
const consumer = await new SourceMapConsumer(rawSourceMap);

const sourcePosition = consumer.originalPositionFor({
line: +line,
Expand All @@ -108,6 +146,8 @@ export const action: ActionFunction = async ({ request }) => {

const file = sourcePosition.source.replace("route-module:", "");

consumer.destroy();

return json({
root,
file: file.replace(root, ""),
Expand Down