Skip to content

[Bug]: Should not remove unused createSnapshot #894

@colinaaa

Description

@colinaaa

System Info

System:
OS: macOS 14.6.1
CPU: (12) arm64 Apple M2 Max
Memory: 4.78 GB / 96.00 GB
Shell: 5.9 - /bin/zsh
npmPackages:
@lynx-js/qrcode-rsbuild-plugin: workspace:* => 0.3.6
@lynx-js/react: workspace:* => 0.108.1
@lynx-js/react-rsbuild-plugin: workspace:* => 0.9.10
@lynx-js/rspeedy: workspace:* => 0.9.5
@lynx-js/types: ^3.3.0 => 3.3.0

Details

Currently, we would add a /*#__PURE__*/ to createSnapshot calls:

snapshot_create_call = match snapshot_create_call {
Expr::Call(mut call) => {
let pure_span = Span::dummy_with_cmt();
self.comments.add_pure_comment(pure_span.lo);
call.span = pure_span;
Expr::Call(call)
}
_ => unreachable!(),
};

This would cause error if a JSX (or snapshot) is created in a background-only context. The following errors could happen:

  1. main-thread.js exception: cannot read property 'update' of undefined

    this.__snapshot_def.update![index]!(this, index, oldValue);

  2. main-thread.js exception: cannot convert to object

    const { create, slot, isListHolder, cssId, entryName } = this.__snapshot_def;

Reproduce link

No response

Reproduce Steps

import { useState, useEffect } from '@lynx-js/react'

export function App() {
  const [jsx, setJSX] = useState(null)
  
  useEffect(() => {
    setJSX(<text>Hello ReactLynx</text>)
  })

  return <view>{jsx}</view>
}

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions