Skip to content

Conversation

@Rich-Harris
Copy link
Member

This implements sourcemapped stack traces for SSR errors in dev and prod. We might argue that we don't want sourcemaps in prod, which could certainly make life easier since source-map is a cumbersome dependency (as it's not pure JS — not sure if it will even work everywhere we want to deploy to).

Also, it needs fs so presumably wouldn't work in a cloudflare worker, for example.

Also also, the filenames are wrong because of this bug: FredKSchott/snowpack#1941

}

try {
const { contents } = await snowpack.loadUrl(address, { isSSR: true, encoding: 'utf8' });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought sourcemap file URLs were paths from the project root on the file system. It might be helpful to add a comment explaining when this would occur. I'm also wondering about the fact that this is needed here and not in page.js

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the Resolving sources section of the standard,

If the sources are not absolute URLs after prepending of the “sourceRoot”, the sources are resolved relative to the SourceMap (like resolving script src in a html document).

In other words, to find the original file for a give segment, find the index into the sources array, and do path.resolve(sourcemap_file, source). There's some ambiguity here because information gets lost between the filesystem and a webserver, but this is the most reliable way to reconstruct a filepath.

I'm also wondering about the fact that this is needed here and not in page.js

loadUrl is invoked for things other than rendering pages (e.g. setup, endpoints)

Copy link
Member

@benmccann benmccann Dec 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we need to call loadUrl for endpoints and not pages?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's called for both

@benmccann benmccann linked an issue Dec 12, 2020 that may be closed by this pull request
@@ -1,5 +1,5 @@
import devalue from 'devalue';
import { createReadStream, existsSync } from 'fs';
import { createReadStream, existsSync, fstat, readFileSync } from 'fs';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fstat is unused

@Rich-Harris
Copy link
Member Author

Decided to remove the sourcemapping from prod, for now — just trades one set of headaches for another. Could be revisited in future.

@Rich-Harris Rich-Harris merged commit 8a55f7b into master Dec 13, 2020
@Rich-Harris Rich-Harris deleted the gh-260-eval branch December 13, 2020 00:48
@benmccann benmccann mentioned this pull request Dec 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Source map stack traces

3 participants