-
Notifications
You must be signed in to change notification settings - Fork 5.1k
fix(ct): Don't bloat metainfo.json file when # or ? is present in id #39074
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
Conversation
|
@mikstime Thank you for the PR! Is there any way you can share a repro, or even better - turn that into a test? That would help us to review and prevent future regressions. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Here is an example https://github.com/mikstime/playwright |
Wonderful! Could you please add a test to |
|
@microsoft-github-policy-service agree |
Sure. Thank you for the instructions. |
| if (!path.isAbsolute(id)) | ||
| return; | ||
| const normalizedId = path.normalize(id); | ||
| const normalizedId = path.normalize(id).split(/\?|#/)[0]; |
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.
- I think we should strip
?and#before the line 292, just in case there was something like/..in the query params or hash. - It would be great to add a comment explaining/having an example of an import with a query param.
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.
Fixed. I’ve stripped ? and # before line 292 and added a comment with an example of an import that includes query parameters.
For context: even without stripping, path.isAbsolute would still treat such paths as absolute. According to the Node.js documentation, paths like /baz/.. are considered absolute, and this also applies when query params or hashes are present, e.g.:
path.isAbsolute('C:/foo/..'); // true
path.isAbsolute('C:\\foo\\..'); // true
path.isAbsolute('/baz/..'); // true
path.isAbsolute('/baz/../..'); // true
This is also true:
> p.isAbsolute('/dir/file#x=../../b.png')
true
> p.isAbsolute('/dir/file?x=../../b.png')
true
That said, removing ? and # up front makes the intent clearer and avoids any edge cases involving traversal in query or hash parts.
| expect(result.passed).toBe(1); | ||
| }); | ||
|
|
||
| test('should remove ? or # from deps in metainfo.json', async ({ runInlineTest }, testInfo) => { |
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.
Thank you for the test, this really helped!
Just to understand the scenario better, do you have a custom loader/plugin/something else that handles query params? What's the actual usecase of yours, not the toy example we have here?
Can we have a test that resembles real life? IIUC, this should manifest in watch not triggering when you change a styles file that was imported as './style.css?inline'. At least, that's the impression I get from reading vite docs. If so, we can add a simple test next to should watch component when editing util.
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.
Just to understand the scenario better, do you have a custom loader/plugin/something else that handles query params? What's the actual usecase of yours, not the toy example we have here?
We use a Vite plugin that transforms source code and appends query parameters to module imports. These query params are used to alter compilation behavior based on the user agent.
If so, we can add a simple test next to should watch component when editing util.
Sure. I’ve added two tests:
- One that directly covers the query-param import case (e.g. style.css?inline), matching the real-world scenario described above.
- Another that exercises the same behavior through a story file, since playwright compiles these cases differently.
dgozman
left a comment
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.
This looks great, thank you for following through!
This comment has been minimized.
This comment has been minimized.
|
@mikstime It seems like this broke our component tests. Could you please take a look? You can run |
This comment has been minimized.
This comment has been minimized.
Sorry about that — looks like I dropped a small but important guard during the rebase: Must be working now. |
Test results for "tests 1"4 failed 5 flaky38565 passed, 843 skipped Merge workflow run. |
Can't reproduce locally on macOS + node 20. Can it be a fluke? Tests passing locally |
Test results for "MCP"10 failed 4769 passed, 135 skipped Merge workflow run. |
dgozman
left a comment
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.
All the related tests are passing, merging in. Thank you for the fix!
Proposal
Remove the
?or#part from dependencies in themetainfo.jsonfile.Description
@playwright/experimental-ct-coregenerates ametainfo.jsonfile used for caching and other optimizations performed by Playwright under the hood.The current implementation relies on a Vite plugin to generate this file. However, Vite prohibits the usage of
#and?in file names, meaning there is no reason to store them in themetainfo.jsonfile.We experienced two major issues with the current behavior:
Our
metainfo.jsonfile exceeded 512MB, which is the hard limit for theJSON.parse()method, resulting in unexpected crashesThis data was serialized and deserialized each time tests ran, resulting in a 4x slowdown of tests in our project
Example
Metainfo.json file is reduced from 1.4M to 4.0K in provided example
https://github.com/mikstime/playwright