-
Notifications
You must be signed in to change notification settings - Fork 38
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
Clean up addons injection script and fix bugs in library #227
Conversation
We should still figure out moving these files in - #226
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.
GitHub diff is 👎 here
This is better, but not by much:
I've tested this against projects with large response pages and the exception is actually caught now, and the response falls back to the origin response. The next change will be trying to catch this through streaming and avoiding buffering the entire request. |
If `Response.clone()` is used without `await` the resulting instance has missing attributes, like `url = null`. The docs do not indicate that `clone()` is async however, so it's not clear why this is required. With this, and more careful response instance usage, most of the cases of dangling, unused, cloned responses have been removed. Now, any response that is used is cloned right as we use it and evaluate the body. This is important, as `response.body` is ultimately what causes the request to buffer.
c1c14e9
to
bea78fb
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.
tests 😍
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 don't love all the explicit test logic in the actual code, but seems it's necessary from the comments around it. Overall this looks similar to what we had, and the logic seems the same. I'm not really knowledgable enough about Workers or JS patterns to review that stuff, but the flow seems reasonable, with a lot more async 😨
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 really good to me. I'm happy we have tests 🧪 now and a pattern to keep adding more 💯
It seems the main change here is the usage of the lower-level API fetch
and .passThroughOnException()
that allow us to catch errors on a try/catch
when transforming the clone()
d response. I don't fully understand the details behind this, but I think I get the big picture here.
I left some suggestions and questions that will allow me to understand a little more some missing pieces.
I'm trying to test this locally, but it seems the paths for some of the Docker files are wrong. I'm getting this error when running inv docker.build
:
=> ERROR [wrangler 2/6] COPY package.json /usr/src/app/packages/addons-inject/ 0.0s
=> ERROR [wrangler 3/6] COPY index.js /usr/src/app/packages/addons-inject/ 0.0s
=> ERROR [wrangler 4/6] COPY wrangler.toml /usr/src/app/packages/addons-inject/ 0.0s
------
> [wrangler 2/6] COPY package.json /usr/src/app/packages/addons-inject/:
------
------
> [wrangler 3/6] COPY index.js /usr/src/app/packages/addons-inject/:
------
------
> [wrangler 4/6] COPY wrangler.toml /usr/src/app/packages/addons-inject/:
------
failed to solve: failed to compute cache key: failed to calculate checksum of ref UPQU:UMYX:4FAE:CRS7:GXRC:2DRM:5B5J:CRJO:MLEW:4WNJ:5M75:ZC7N::p64btx7uytedu4ry4kp8bwbzq: "/wrangler.toml": not found
I think we need to use relative paths using readthedocs.org
as working path.
After building the images properly I'm getting this error:
|
Just a note that before merging this PR we should fix the wrangler Docker container so it works with the pattern we already have and builds correctly. |
dockerfiles/docker-compose.yml
Outdated
networks: | ||
readthedocs: | ||
working_dir: /usr/src/app/packages/addons-inject/ | ||
command: [ | ||
"wrangler", |
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 need this to be as follows to work properly when executing inv docker.up
"wrangler", | |
"node_modules/.bin/wrangler", |
I fixed this and left the solution as suggestions. I was able to build the Docker images and run it as usual with those changes. |
There is a lot here to modernize this library and fix a number of bugs:
fetch
event and instead usefetch()
exported functionResponse
instances, and when this happens.searchtools.js
override responds as text/plain content type addons#410