Skip to content
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: Prod build collections cache can be modified #10709

Closed
wants to merge 11 commits into from

Conversation

rishi-raj-jain
Copy link
Contributor

@rishi-raj-jain rishi-raj-jain commented Apr 7, 2024

fixes #10700

Changes

  • What does this change?

  • Be short and concise. Bullet points can help!

  • Before/after screenshots can help as well.

  • Don't forget a changeset! pnpm exec changeset

Testing

Docs

I do not think docs are required as this is a patch for the existing functionality?

Copy link

changeset-bot bot commented Apr 7, 2024

🦋 Changeset detected

Latest commit: 051f6a7

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Apr 7, 2024
@rishi-raj-jain rishi-raj-jain changed the title Update runtime.ts fix: Prod build collections cache can be modified Apr 7, 2024
@florian-lefebvre
Copy link
Member

Do you think you can tackle #9306 as well? Seems similar

@rishi-raj-jain
Copy link
Contributor Author

@florian-lefebvre

I think this PR addresses that as well (already) as it's not returning a reference anymore. What do you think?

@ematipico
Copy link
Member

Can we have a changeset? Also, can you update the template with the relevant information on how you tested the fix?

@florian-lefebvre florian-lefebvre linked an issue Apr 8, 2024 that may be closed by this pull request
1 task
@@ -107,6 +104,8 @@ export function createGetCollection({
);
cacheEntriesByCollection.set(collection, entries);
}
// Always return a new instance so consumers can safely mutate it
entries = [...cacheEntriesByCollection.get(collection)!];
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be expensive for large collections. Given this is corner case, can we use Object.freeze when we set it instead? That would have similar effect (can't push, splice, etc) but without doing it on ever request.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Can not freeze the cached collection as individual pages can still expect to sort the collection

Where did you read this? I just tried to use Object.freeze, and it works

@matthewp
Copy link
Contributor

@rishi-raj-jain do you still plan on working on this?

@rishi-raj-jain
Copy link
Contributor Author

@matthewp

Hey yeah, let me get on to this by tomorrow.

@rishi-raj-jain
Copy link
Contributor Author

I am unable to locate the tests for content collection, may you help me with that, @ematipico?

@ematipico
Copy link
Member

There's a content-collections.test.js file. You could use that one. We just need to create a new test case, and make sure it's fixed by this PR

@rishi-raj-jain
Copy link
Contributor Author

There's a content-collections.test.js file. You could use that one. We just need to create a new test case, and make sure it's fixed by this PR

Yup, the tests already cover this as recorded in my observation at #10709 (comment)

@ematipico
Copy link
Member

There's a content-collections.test.js file. You could use that one. We just need to create a new test case, and make sure it's fixed by this PR

Yup, the tests already cover this as recorded in my observation at #10709 (comment)

I am not sure I understand. We want to make sure that the original content collection isn't modified and that test case doesn't do that.

@rishi-raj-jain
Copy link
Contributor Author

There's a content-collections.test.js file. You could use that one. We just need to create a new test case, and make sure it's fixed by this PR

Yup, the tests already cover this as recorded in my observation at #10709 (comment)

I am not sure I understand. We want to make sure that the original content collection isn't modified and that test case doesn't do that.

I aimed to prevent modifications to the cached collection, but I think my understanding is not correct. I'm going to close this so that the issue doesn't end up being stalled due to me.

@rishi-raj-jain rishi-raj-jain deleted the patch-2 branch April 28, 2024 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
4 participants