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: conflict between rewrite and actions middleware #11052

Merged
merged 6 commits into from
May 15, 2024

Conversation

florian-lefebvre
Copy link
Member

Changes

  • When using rewrite with actions, a case where locals._actionsInternal is reassigned can occur. However, there's a protection to disable reassigning it so it fails. This PR does not attempt to reassign if it already exists

Testing

Manual patch in a private project

Docs

N/A, bug fix

Copy link

changeset-bot bot commented May 15, 2024

🦋 Changeset detected

Latest commit: 960c8d4

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 May 15, 2024
Copy link
Contributor

@bholmesdev bholmesdev left a comment

Choose a reason for hiding this comment

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

Question about a conditional check for the success case. Also curious what is triggering the reassignment? Is it an object spread?

packages/astro/src/actions/runtime/middleware.ts Outdated Show resolved Hide resolved
@florian-lefebvre
Copy link
Member Author

florian-lefebvre commented May 15, 2024

Well I think the case is kinda tricky but basically, I have this middleware

(context, next) => {
	context.locals.data = null
	context.locals.foo = async (data) => {
		context.locals.data = data
		return await next("/bar")
	}

	return next()
}

then I can call it in an astro route:

return await Astro.locals.bar("abc")

I need to call next to be able to keep the data in the rewritten page, I can't call rewrite

@bholmesdev bholmesdev merged commit a05ca38 into main May 15, 2024
13 checks passed
@bholmesdev bholmesdev deleted the fix/reassign-actions-internal branch May 15, 2024 16:49
@astrobot-houston astrobot-houston mentioned this pull request May 15, 2024
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
Development

Successfully merging this pull request may close these issues.

3 participants