-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Fix HMR for action files during development #16932
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
Open
fkatsuhiro
wants to merge
2
commits into
withastro:main
Choose a base branch
from
fkatsuhiro:fix/actions-hmr-invalidate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+124
−4
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'astro': patch | ||
| --- | ||
|
|
||
| Fixes HMR for action files during development. Editing files in `src/actions/` now takes effect on the next request without requiring a dev server restart. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { describe, it } from 'node:test'; | ||
| import { createBasicPipeline } from '../test-utils.ts'; | ||
|
|
||
| describe('actions HMR cache invalidation', () => { | ||
| it('clearActions() resets the cached resolved actions', async () => { | ||
| const firstActions = { server: { greet: () => 'hello' } } as any; | ||
| const secondActions = { server: { greet: () => 'updated' } } as any; | ||
|
|
||
| let callCount = 0; | ||
| const pipeline = createBasicPipeline({ | ||
| manifest: { | ||
| actions: () => { | ||
| callCount++; | ||
| return callCount === 1 ? firstActions : secondActions; | ||
| }, | ||
| }, | ||
| } as any); | ||
|
|
||
| // First call should invoke the factory and cache the result. | ||
| const result1 = await pipeline.getActions(); | ||
| assert.equal(callCount, 1); | ||
| assert.equal(result1, firstActions); | ||
|
|
||
| // Subsequent call should return the cached value, not call the factory again. | ||
| const result2 = await pipeline.getActions(); | ||
| assert.equal(callCount, 1, 'factory should not be called again while cached'); | ||
| assert.equal(result2, firstActions); | ||
|
|
||
| // After clearing, the next call should invoke the factory again. | ||
| pipeline.clearActions(); | ||
| const result3 = await pipeline.getActions(); | ||
| assert.equal(callCount, 2, 'factory should be called again after clearActions()'); | ||
| assert.equal(result3, secondActions); | ||
| }); | ||
|
|
||
| it('getActions() returns NOOP when no actions factory is configured', async () => { | ||
| const pipeline = createBasicPipeline(); | ||
| const result = await pipeline.getActions(); | ||
| assert.ok(result, 'should return a non-undefined value'); | ||
| assert.deepEqual(result.server, {}, 'should return noop actions with empty server'); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 something that shouldn't happen in production. Clearing actions in production is incorrect.