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 issue where, in some situations, the immediate-invoker helper manager (used when you use resourceFactory) was not correctly destroying the previous instance of a resource (such as when args change)) #1135

Merged
merged 6 commits into from
Jun 18, 2024

Conversation

NullVoxPopuli
Copy link
Owner

@NullVoxPopuli NullVoxPopuli commented Jun 17, 2024

Fix #1134

The issue seems specific to vanilla rendering, where your resource isn't surrounded with an if block.

Copy link

stackblitz bot commented Jun 17, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

vercel bot commented Jun 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ember-resources-0a9q ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 18, 2024 8:51pm

Copy link
Contributor

github-actions bot commented Jun 17, 2024

Estimated impact to a consuming app, depending on which bundle is imported

js min min + gzip min + brotli
/index.js 14.44 kB 2.13 kB 930 B 773 B

@NullVoxPopuli NullVoxPopuli changed the title title pending -- not sure if / what issue yet Fix issue where the immediate-invoker helper manager (used when you use resourceFactory) was not correctly destroying the previous instance of a resource (such as when args change)) Jun 18, 2024
@NullVoxPopuli NullVoxPopuli marked this pull request as ready for review June 18, 2024 20:49
@NullVoxPopuli NullVoxPopuli changed the title Fix issue where the immediate-invoker helper manager (used when you use resourceFactory) was not correctly destroying the previous instance of a resource (such as when args change)) Fix issue where, in some situations, the immediate-invoker helper manager (used when you use resourceFactory) was not correctly destroying the previous instance of a resource (such as when args change)) Jun 18, 2024
@@ -14,9 +14,6 @@ type ResourceFactory<Value = any, Args = any> = (...args: SpreadFor<Args>) => Va

interface State {
cache: ReturnType<typeof invokeHelper>;
fn: any;
Copy link
Owner Author

Choose a reason for hiding this comment

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

These were all unused

let result = invokeHelper(cache, resource);

if (previous) {
destroy(previous);
Copy link
Owner Author

Choose a reason for hiding this comment

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

the fix

@@ -72,6 +78,9 @@ class ResourceInvokerManager {
}

getDestroyable({ cache }: State) {
/**
* This is the parent cache, from `createHelper`
Copy link
Owner Author

Choose a reason for hiding this comment

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

with nested caches, I had a hard time knowing which thing I was dealing with when, so I added some context

@@ -186,6 +186,7 @@ export function resource<Value>(
let internalConfig: InternalFunctionResourceConfig<Value> = {
definition: context as ResourceFunction<Value>,
type: 'function-based',
name: 'Resource',
Copy link
Owner Author

Choose a reason for hiding this comment

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

Helps with debug output when errors from Glimmer print to the console


function getDebugName(obj: object) {
if ('name' in obj) {
return `Resource Function: ${obj.name}`;
Copy link
Owner Author

Choose a reason for hiding this comment

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

Helps with debug output when errors from Glimmer print to the console

@@ -42,15 +42,21 @@
"allowImportingTsExtensions": true,

// require extensions
"module": "Node16",
"moduleResolution": "Node16",
// "module": "Node16",
Copy link
Owner Author

Choose a reason for hiding this comment

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

fixes local dev experience

let app = new EmberApp(defaults, {
trees: {
app: sideWatch('app', { watching: [path.join(__dirname, '../ember-resources')] }),
Copy link
Owner Author

Choose a reason for hiding this comment

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

allows me to not have to restart the app when I re-compile the addon (which is an injected dependency)

@NullVoxPopuli NullVoxPopuli merged commit b386dac into main Jun 18, 2024
26 checks passed
@NullVoxPopuli NullVoxPopuli deleted the non-block-clean-up-change branch June 18, 2024 20:55
@github-actions github-actions bot mentioned this pull request Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Potential issue with non-block updates deferring cleanup to their parent context
1 participant