-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(turbopack-ecmascript): support urlrewritebehavior::full #6413
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 11 Ignored Deployments
|
✅ This change can build |
🟢 CI successful 🟢Thanks |
Linux Benchmark for 10232f6Click to view benchmark
|
|
├───────────────────────────────┼─────────────────────────────────────────────────────────────────────────┼────────────────────────────────────────────────┼───────────────────────┤ | ||
│ Relative │ new URL(__turbopack_relative_url__(__turbopack_require__(urlId)), base) │ new URL(__turbopack_relative_url__(url), base) │ new URL(url, base) │ | ||
│ Full(RenderingClient::Client) │ new URL(__turbopack_require__(urlId), "location.origin") │ new URL(url, "location.origin") │ new URL(url, base) │ | ||
│ Full(RenderingClient::..) │ new URL(__turbopack_resolve_module_id_path__(urlId)) │ new URL(url, base) │ new URL(url, base) │ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need another module wrapper function for this? Why can't we derive this from CWD
or similar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have cwd, but that's not composable with relative path url to its output asset.
The simpliest example is like new URL('../../public/img.png', import.meta.url)
: we have correct import.meta.url points to yhe cwd of the module, but _turbopack_require'd module points to the output distdir's asset with asset prefix so can't relate those two directlt.
This is the actual problem I struggled to solve without these wrapper, if there's a way to get a full phsyical path without asset prefix it'd be great. I feel I may miss something.
ca15108
to
f19102d
Compare
Linux Benchmark for b30a55aClick to view benchmark
|
f19102d
to
48bd511
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can add an execution turbopack-test to test this
Linux Benchmark for 0410e52Click to view benchmark
|
63a1305
to
8010a70
Compare
Gave a quick peek, and then realized test uses different runtime to the runtime next-swc's turbopack uses, which doesn't have any foundation support such as runtime's absolute path, etcs. I'd like to tackle this as separate PR later as have to port runtime's feature other than my changes. |
Fine to me, at least run it against the next.js test case to verify it's working |
Yes, as shared in the slack thread vercel/next.js#58404 verifies new url tests are passing (vercel/next.js@4e63956#diff-2731c6687251176e46f1aa219fe2c059c9a13b61f0a5035d9b5073c9fc10258e) . Failed test is flaky I believe. |
8010a70
to
13e7f62
Compare
Linux Benchmark for 9c4b9bcClick to view benchmark
|
13e7f62
to
9261cb7
Compare
a100e8b
to
2720b60
Compare
2720b60
to
b98c5a8
Compare
b98c5a8
to
8152044
Compare
Description
This PR tries to correct the behavior of
UrlRewriteBehavior::Full
.With
UrlRewriteBehavior::Full
, it is expectednew URL(url, base)
resolves to the absolute full path to the requested url. Previously, this didn't work for 2 reasonsurl
to the emitted output pathbase
to non-relative to the above output pathin result resolving won't give the correct path.
I tried a couple of approaches if it's possible to construct full path directly when there's a referenced asset, but wasn't able to make it work. Instead this PR relies on the new runtime fn wraps
__turbopack_require__
, calculate the full path with the absolute path runtime already have + resolved asset path. Since emitted asset contains its output with assetPrefix, exports it into the runtime as well to strips it out.Overall behaviors across different condition are illustarted here:
https://github.com/vercel/turbo/compare/url-full-resolve-context?expand=1#diff-bb24150ae91f0fa7b3001d17e597f89d3e16f5e0f4894acb4bd0499fbcd73793R134
Closes PACK-1924