@devvit/ui-renderer 0.9.6 → 0.9.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,9 @@
1
1
  import { LitElement, PropertyValues } from 'lit';
2
2
  import '@reddit/faceplate-ui/templateRenderingStrategy/clientStrategy.js';
3
- import type { Metadata } from '@devvit/protos';
3
+ import type { LinkedBundle, Metadata } from '@devvit/protos';
4
4
  import { Block, RenderPostResponse } from '@devvit/protos';
5
5
  import type { ActorRef } from '@devvit/runtimes/common/runtime/ActorRef.js';
6
+ import { BrowserLiteClient } from '@devvit/runtime-lite/BrowserLiteClient.js';
6
7
  import './devvit-animation-player.js';
7
8
  import '../blocks/components/devvit-blocks-renderer.js';
8
9
  declare global {
@@ -15,11 +16,15 @@ export declare class DevvitCustomPost extends LitElement {
15
16
  actorRef?: ActorRef;
16
17
  metadata?: Metadata;
17
18
  postId?: string;
19
+ localRuntimeCode?: Blob;
20
+ bundle?: LinkedBundle;
21
+ useSandbox: boolean;
18
22
  renderResponse?: RenderPostResponse;
19
23
  rootBlock?: Block;
24
+ localClient?: BrowserLiteClient;
20
25
  connectedCallback(): void;
21
26
  disconnectedCallback(): void;
22
- protected willUpdate(changedProperties: PropertyValues): void;
27
+ protected willUpdate(changedProperties: PropertyValues): Promise<void>;
23
28
  render(): import("lit-html").TemplateResult<1>;
24
29
  }
25
30
  declare global {
@@ -1 +1 @@
1
- {"version":3,"file":"devvit-custom-post.d.ts","sourceRoot":"","sources":["../../library/src/client/devvit-custom-post.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,UAAU,EAAE,cAAc,EAAE,MAAM,KAAK,CAAC;AAIvD,OAAO,kEAAkE,CAAC;AAG1E,OAAO,KAAK,EAMV,QAAQ,EAIT,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,KAAK,EAKL,kBAAkB,EAEnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,QAAQ,EAAE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AC;IAGpB,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAGpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAGhB,gBAAgB,CAAC,EAAE,IAAI,CAAC;IAGxB,MAAM,CAAC,EAAE,YAAY,CAAC;IAGtB,UAAU,EAAE,OAAO,CAAQ;IAG3B,cAAc,CAAC,EAAE,kBAAkB,CAAC;IAGpC,SAAS,CAAC,EAAE,KAAK,CAAC;IAalB,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAMvB,iBAAiB;IAKjB,oBAAoB;cASJ,UAAU,CAAC,iBAAiB,EAAE,cAAc;IAmC5D,MAAM;CAiIhB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,oBAAoB,EAAE,gBAAgB,CAAC;KACxC;CACF"}
@@ -6,12 +6,15 @@ import PQueue from 'p-queue';
6
6
  import '@reddit/faceplate-ui/templateRenderingStrategy/clientStrategy.js';
7
7
  import { customEvent } from '@reddit/faceplate/lib/custom-event.js';
8
8
  import { Block, BlockRenderEventType, BlockStackDirection, CustomPostDefinition, EffectType, RenderPostResponse, UIEventHandlerDefinition, } from '@devvit/protos';
9
+ import { BrowserLiteClient } from '@devvit/runtime-lite/BrowserLiteClient.js';
10
+ import { isCircuitBreaker } from '@devvit/runtime-lite/CircuitBreaker.js';
9
11
  import './devvit-animation-player.js';
10
12
  import '../blocks/components/devvit-blocks-renderer.js';
11
13
  let DevvitCustomPost = class DevvitCustomPost extends LitElement {
12
14
  constructor() {
13
15
  super(...arguments);
14
16
  _DevvitCustomPost_instances.add(this);
17
+ this.useSandbox = true;
15
18
  _DevvitCustomPost_postData.set(this, void 0);
16
19
  _DevvitCustomPost_appState.set(this, {});
17
20
  _DevvitCustomPost_lastRequest.set(this, void 0);
@@ -33,7 +36,13 @@ let DevvitCustomPost = class DevvitCustomPost extends LitElement {
33
36
  event,
34
37
  state: __classPrivateFieldGet(this, _DevvitCustomPost_instances, "a", _DevvitCustomPost_state_get),
35
38
  };
36
- const call = __classPrivateFieldGet(this, _DevvitCustomPost_uiEventHandlerActor, "f")?.HandleUIEvent(req, this.metadata);
39
+ let call;
40
+ try {
41
+ call = (await this.localClient?.call('HandleUIEvent', req, this.metadata));
42
+ }
43
+ catch {
44
+ call = await __classPrivateFieldGet(this, _DevvitCustomPost_uiEventHandlerActor, "f")?.HandleUIEvent(req, this.metadata);
45
+ }
37
46
  if (call) {
38
47
  const res = await call;
39
48
  __classPrivateFieldSet(this, _DevvitCustomPost_appState, res.state ?? {}, "f");
@@ -59,15 +68,36 @@ let DevvitCustomPost = class DevvitCustomPost extends LitElement {
59
68
  window.clearTimeout(__classPrivateFieldGet(this, _DevvitCustomPost_rerenderTimeout, "f"));
60
69
  }
61
70
  this.removeEventListener('devvit-user-action', __classPrivateFieldGet(this, _DevvitCustomPost_handleUserAction, "f"));
71
+ this.localClient?.quit();
62
72
  }
63
- willUpdate(changedProperties) {
73
+ async willUpdate(changedProperties) {
64
74
  if (changedProperties.has('postId')) {
65
75
  __classPrivateFieldSet(this, _DevvitCustomPost_postData, this.postId !== undefined ? { __postData: { thingId: this.postId } } : undefined, "f");
66
76
  }
77
+ if (changedProperties.has('localRuntimeCode') && this.localRuntimeCode) {
78
+ this.localClient?.quit();
79
+ this.localClient = new BrowserLiteClient(this.localRuntimeCode);
80
+ }
81
+ let actorRefChanged = false;
67
82
  if (changedProperties.has('actorRef')) {
68
83
  __classPrivateFieldSet(this, _DevvitCustomPost_customPostActor, this.actorRef?.As(CustomPostDefinition), "f");
69
84
  __classPrivateFieldSet(this, _DevvitCustomPost_uiEventHandlerActor, this.actorRef?.As(UIEventHandlerDefinition), "f");
70
- __classPrivateFieldGet(this, _DevvitCustomPost_instances, "m", _DevvitCustomPost_initialRender).call(this);
85
+ actorRefChanged = true;
86
+ }
87
+ let bundleChanged = false;
88
+ if (changedProperties.has('bundle')) {
89
+ this.localClient?.quit();
90
+ bundleChanged = true;
91
+ }
92
+ if (this.actorRef && (actorRefChanged || bundleChanged)) {
93
+ if (this.bundle) {
94
+ // offline/online, defer initialRender for offline client
95
+ await this.localClient?.loadBundle(this.bundle, this.useSandbox);
96
+ }
97
+ else {
98
+ // online only
99
+ __classPrivateFieldGet(this, _DevvitCustomPost_instances, "m", _DevvitCustomPost_initialRender).call(this);
100
+ }
71
101
  }
72
102
  }
73
103
  render() {
@@ -90,9 +120,25 @@ _DevvitCustomPost_postData = new WeakMap(), _DevvitCustomPost_appState = new Wea
90
120
  __classPrivateFieldGet(this, _DevvitCustomPost_instances, "m", _DevvitCustomPost_renderPost).call(this, __classPrivateFieldGet(this, _DevvitCustomPost_renderRequest, "f").call(this, BlockRenderEventType.RENDER_USER_ACTION, actionId, data));
91
121
  }, _DevvitCustomPost_effectEventRender = function _DevvitCustomPost_effectEventRender(effectType, effectData) {
92
122
  __classPrivateFieldGet(this, _DevvitCustomPost_instances, "m", _DevvitCustomPost_renderPost).call(this, __classPrivateFieldGet(this, _DevvitCustomPost_renderRequest, "f").call(this, BlockRenderEventType.RENDER_EFFECT_EVENT, effectType, effectData));
93
- }, _DevvitCustomPost_renderPost = function _DevvitCustomPost_renderPost(req) {
123
+ }, _DevvitCustomPost_renderPost = function _DevvitCustomPost_renderPost(req, circuitBreak = false) {
94
124
  void __classPrivateFieldGet(this, _DevvitCustomPost_rpcQueue, "f").add(async () => {
95
- const call = await __classPrivateFieldGet(this, _DevvitCustomPost_customPostActor, "f")?.RenderPost(req, this.metadata);
125
+ let call;
126
+ try {
127
+ if (circuitBreak) {
128
+ throw new Error();
129
+ }
130
+ call = (await this.localClient?.call('RenderPost', req, this.metadata));
131
+ }
132
+ catch (e) {
133
+ if (isCircuitBreaker(e) && e.response) {
134
+ call = e.response;
135
+ // queue up follow-up call
136
+ __classPrivateFieldGet(this, _DevvitCustomPost_instances, "m", _DevvitCustomPost_renderPost).call(this, req, true);
137
+ }
138
+ else {
139
+ call = await __classPrivateFieldGet(this, _DevvitCustomPost_customPostActor, "f")?.RenderPost(req, this.metadata);
140
+ }
141
+ }
96
142
  if (call) {
97
143
  this.renderResponse = await call;
98
144
  if (this.renderResponse.state) {
@@ -105,7 +151,9 @@ _DevvitCustomPost_postData = new WeakMap(), _DevvitCustomPost_appState = new Wea
105
151
  }
106
152
  await __classPrivateFieldGet(this, _DevvitCustomPost_instances, "m", _DevvitCustomPost_handleEffects).call(this, this.renderResponse.effects);
107
153
  }
108
- });
154
+ },
155
+ // Cut in line to re-render from server response immediately
156
+ { priority: circuitBreak ? 100 : 0 });
109
157
  }, _DevvitCustomPost_handleEffects = async function _DevvitCustomPost_handleEffects(effects) {
110
158
  effects.forEach((effect) => {
111
159
  if (effect.type === EffectType.EFFECT_RERENDER_UI) {
@@ -133,6 +181,18 @@ __decorate([
133
181
  property({ attribute: false }),
134
182
  __metadata("design:type", String)
135
183
  ], DevvitCustomPost.prototype, "postId", void 0);
184
+ __decorate([
185
+ property({ attribute: false }),
186
+ __metadata("design:type", Blob)
187
+ ], DevvitCustomPost.prototype, "localRuntimeCode", void 0);
188
+ __decorate([
189
+ property({ attribute: false }),
190
+ __metadata("design:type", Object)
191
+ ], DevvitCustomPost.prototype, "bundle", void 0);
192
+ __decorate([
193
+ property({ attribute: false }),
194
+ __metadata("design:type", Boolean)
195
+ ], DevvitCustomPost.prototype, "useSandbox", void 0);
136
196
  __decorate([
137
197
  state(),
138
198
  __metadata("design:type", Object)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@devvit/ui-renderer",
3
- "version": "0.9.6",
3
+ "version": "0.9.8",
4
4
  "license": "BSD-3-Clause",
5
5
  "repository": {
6
6
  "type": "git",
@@ -47,8 +47,9 @@
47
47
  },
48
48
  "types": "./index.d.ts",
49
49
  "dependencies": {
50
- "@devvit/protos": "0.9.6",
51
- "@devvit/runtimes": "0.9.6",
50
+ "@devvit/protos": "0.9.8",
51
+ "@devvit/runtime-lite": "0.9.8",
52
+ "@devvit/runtimes": "0.9.8",
52
53
  "@lottiefiles/lottie-player": "1.7.1",
53
54
  "p-queue": "7.3.4",
54
55
  "rxjs": "7.5.7"
@@ -73,10 +74,10 @@
73
74
  "lit": "^2.0.0"
74
75
  },
75
76
  "devDependencies": {
76
- "@devvit/eslint-config": "0.9.6",
77
- "@devvit/public-api": "0.9.6",
78
- "@devvit/repo-tools": "0.9.6",
79
- "@devvit/tsconfig": "0.9.6",
77
+ "@devvit/eslint-config": "0.9.8",
78
+ "@devvit/public-api": "0.9.8",
79
+ "@devvit/repo-tools": "0.9.8",
80
+ "@devvit/tsconfig": "0.9.8",
80
81
  "@lit/localize": "0.11.4",
81
82
  "@reddit/baseplate": "0.14.0",
82
83
  "@reddit/eslint-plugin-i18n-shreddit": "0.1.0",
@@ -100,5 +101,5 @@
100
101
  "directory": "dist"
101
102
  },
102
103
  "source": "./src/index.ts",
103
- "gitHead": "656833a63ae45857f86b4753f46d9344430e3c8c"
104
+ "gitHead": "1c814515d240366b589bbd65b692bedf9130668b"
104
105
  }